#include "QuoteLvOper.h"
#include "GZip.h"
#include "SocketInterface.h"
#include "HttpTools.h"
#include "FileTools.h"
#include "Tools.h"
#include "TimeTools.h"
#include "DictionaryTools.h"
#include "STInterface.h"

#define			OPER_SEND_LEN				10240		//发送数据的长度

#define			LOC_UDRANGE		"涨跌幅"

enum QUOTE_STATUS_tag{
  QUOTE_STATUS_CONN = 0,
  QUOTE_STATUS_SERVER_DATA,       //服务器数据
  QUOTE_STATUS_SERVER_ERROR,      //服务器错误
  QUOTE_STATUS_SERVER_NO_LOGIN,   //没有登录
  QUOTE_STATUS_SERVER_NO_LEVEL2,  //没有leve2权限
  QUOTE_STATUS_SESSION_TIMEOUT,   //session time out
}QUOTE_STATUS;

/**
 * 功能:
 *		把股票代码添加到最近浏览中
 * 参数:
 *		QUOTELV_OPER	*aArray		操作结构指针
 *		char			*aCode		代码
 *		int				aMaketId	市场ID
 * 返回值:
 *		-
 * 注释:
 *		
 */
QUOTELV_CODE_ARRAY* QuoteLvOper_AddRecViewCode(QUOTELV_CODE_ARRAY *aArray, char* aCode, char aMaketId);

/**
 * 功能:
 *		删除所有的最近浏览数据
 * 参数:
 *		QUOTELV_OPER	*aArray		操作结构指针
 * 返回值:
 *		-
 * 注释:
 *		
 */
void QuoteLvOper_DelAllRecViewCode(QUOTELV_CODE_ARRAY *aArray);

/**
 * 功能:
 *		发送数据
 * 参数:
 *		QUOTELV_OPER	*aOper		操作结构指针
 *		char			*aData		数据源
 *		int				aLen		长度
 *		int				aId			订阅Id
 * 返回值:
 *		-
 * 注释:
 *		
 */
int QuoteLvOper_SendData(QUOTELV_OPER *aOper, char* aData, int aLen);


/**
 * 功能:
 *		发送更新数据字典数据请求
 * 参数:
 *		QUOTELV_OPER	*aOper		操作结构指针
 *		char			*aData		数据源
 *		int				aLen		长度
 *		int				aId			订阅Id
 * 返回值:
 *		-
 * 注释:
 *
 */
int QuoteLvOper_SendDictData(QUOTELV_OPER *aOper, char* aData, int aLen);

/**
 * 功能:
 *		Socket状态回调接受函数
 * 参数:
 *		void *pCBObj            socket状态回调方法对象，这里是QUOTELV_OPER
 *      int nStatus             socket状态码
 * 返回值:
 *		-
 * 注释:
 *		
 */
void QuoteLvOper_StockStatusNotice(void *pCBObj, int nStatus);

/**
 * 功能:
 *		Socket数据回调接受函数
 * 参数:
 *		void *pCBObj            socket状态回调方法对象，这里是QUOTELV_OPER
 *    void *apData            数据
 *    int  anSize             数据大小
 * 返回值:
 *		-
 * 注释:
 *		
 */
void QuoteLvOper_ResedData(void *apObject, void *apData, int anSize);


/**
 * 功能:
 *		Http回调接受函数
 * 参数:
 *		SOCKET_NODE *pHttp		Http操作结构指针
 * 返回值:
 *		-
 * 注释:
 *		
 */
void QuoteLvOper_HttpResedData(HTTP_TOOLS *pHttp, int nType);

/**
 * 功能:
 *		Http短链接请求不需刷新回调接受函数
 * 参数:
 *		SOCKET_NODE *pHttp		Http操作结构指针
 * 返回值:
 *		-
 * 注释:
 *
 */
void QuoteLvOper_HttpNoRefResedData(HTTP_TOOLS *pHttp, int nType);

/**
 * 功能:
 *		解析接受数据
 * 参数:
 *		QUOTELV_OPER	*aOper		操作结构指针
 *		char			*aData		数据源
 *		int				aLen		长度
 * 返回值:
 *		-
 * 注释:
 *		
 */
void QuoteLvOper_ParseData(QUOTELV_OPER *aOper, char* aData, int aLen);

/**
 * 功能:
 *		基金回调接受函数
 * 参数:
 *		HTTP_TOOLS *pHttp		Http数据结构指针
 * 返回值:
 *		-
 * 注释:
 *		
 */
void QuoteLvOper_ResedFundData(HTTP_TOOLS *pHttp, int nType);

/**
 * 功能:
 *		基金净值图回调接受函数
 * 参数:
 *		HTTP_TOOLS *pHttp		Http数据结构指针
 * 返回值:
 *		-
 * 注释:
 *		
 */
void QuoteLvOper_ResedFundVauleData(HTTP_TOOLS *pHttp, int nType);

/**
 * 功能:
 *		基金资讯回调接受函数
 * 参数:
 *		HTTP_TOOLS *pHttp		Http数据结构指针
 * 返回值:
 *		-
 * 注释:
 *		
 */
void QuoteLvOper_ResedFundInfoData(HTTP_TOOLS *pHttp, int nType);

char* QuoteLvOper_PackHead(QUOTELV_OPER *aOper, int aType, int aSubscribeId, TBOOL aIsSubscribe);

/**
 * 功能:
 *		http请求刷新功能
 * 参数:
 *		HTTP_TOOLS *pHttp		Http数据结构指针
 * 返回值:
 *		-
 * 注释:
 *		
 */
void QuoteLvOper_HttpRef(QUOTELV_OPER *aOper);

QUOTELV_CODE_ARRAY* QuoteLvOper_AddRecViewCode(QUOTELV_CODE_ARRAY *aArray, char* aCode, char aMaketId)
{
  //add by jason 修改加入的股票代码为空时的bug
	if (aCode == NULL || strestr(aCode, ""))
	{
		return aArray;
	}
  //end
	
	if (aArray == NULL) {
		aArray = (QUOTELV_CODE_ARRAY *)Tools_Malloc(sizeof(QUOTELV_CODE_ARRAY));
	}
  
	unsigned int hash = 0;
	char phash[8];
	memset(phash,0,8);
  int codeLen = strlen(aCode);
  if (codeLen == 5) {//沪港通 或 港股
    memcpy(phash,aCode,strlen(aCode));
    phash[5] = aMaketId;
  }else{
    memcpy(phash,aCode,CODELV_LEN);
    phash[6] = aMaketId;
  }

	hash = ELFHash(phash);
	
	if (strlen(aArray->pCode.code) == 0)			//第一个数据
	{
		memcpy(aArray->pCode.code,aCode,CODELV_LEN);
		aArray->pCode.maketId = aMaketId;
		aArray->pCode.nHash = hash;
	}
	else
	{
		QUOTELV_CODE_ARRAY *pNewArray = (QUOTELV_CODE_ARRAY *)Tools_Malloc(sizeof(QUOTELV_CODE_ARRAY));
		memcpy(&pNewArray->pCode,&aArray->pCode,sizeof(QUOTELV_CODE));
		pNewArray->pNextCode = aArray->pNextCode;
		memcpy(aArray->pCode.code,aCode,CODELV_LEN);
		aArray->pCode.maketId = aMaketId;
		aArray->pCode.nHash = hash;
		aArray->pNextCode = pNewArray;
		
		
		
		//查找是否存在股票代码
		
		QUOTELV_CODE_ARRAY *pCur = aArray->pNextCode;
		QUOTELV_CODE_ARRAY *pLast = NULL;
		
		while(pCur)
		{	
			if (pCur->pCode.nHash == hash)
			{
				if (pLast == NULL)
				{
					aArray->pNextCode = pCur->pNextCode;
				}
				else
				{
					pLast->pNextCode = pCur->pNextCode;
				}
				
				Tools_Free((void **) &pCur);
				break;
			}
			
			pLast = pCur;
			pCur = pCur->pNextCode;
		}
	}
	
	return aArray;
}

void QuoteLvOper_DelAllRecViewCode(QUOTELV_CODE_ARRAY *aArray)
{
    //addfmy
    if (aArray == NULL) {
        return;
    }
    //addfmy
	QUOTELV_CODE_ARRAY *pNext = aArray->pNextCode;
	QUOTELV_CODE_ARRAY *pCur = aArray;
	
	while(pNext)
	{
		pCur = pNext;
		Tools_Free((void **) &pCur);
		pNext = pCur->pNextCode;
	}
	
}

QUOTELV_CODE* QuoteLvOper_GetRecViewCode(QUOTELV_CODE_ARRAY *aArray, int aIndex)
{
	if (aArray == NULL || aIndex < 0)
	{
		return NULL;
	}
	
	if (aIndex == 0)
	{
		if (strlen(aArray->pCode.code) > 0)
		{
			return &aArray->pCode;
		}
		
		return NULL;
	}
	
	QUOTELV_CODE_ARRAY *pNext = aArray->pNextCode;
	int count = 1;
	
	while(pNext)
	{
		if (count == aIndex)
		{
			return &pNext->pCode;
		}
		
		pNext = pNext->pNextCode;
		count++;
	}
	
	return NULL;
	
}

int QuoteLvOper_GetRecViewCount(QUOTELV_CODE_ARRAY *aArray)
{
	if (aArray == NULL)
	{
		return 0;
	}
	
	int count = 0;
	QUOTELV_CODE_ARRAY *pNext = aArray->pNextCode;
	
	while(pNext)
	{
		pNext = pNext->pNextCode;
		count++;
	}
	
	if (strlen(aArray->pCode.code) > 0)
	{
		count++;
	}
	
	return count;
}

/**
 * 功能:
 *		设置行情操作结构状态通知
 * 参数:	
 *		QUOTELV_OPER*	行情操作结构指针
 * 返回值:
 *		-
 * 注释:
 *		
 */
void QuoteLvOper_SetStatusNotice(QUOTELV_OPER* pOper)
{
  
}


QUOTELV_OPER* QuoteLvOper_New()
{
	int i = 0;
	int j = 0;
	printf("\nsize:%5.2f\n",(sizeof(QUOTELV_OPER)/1024.0));
	QUOTELV_OPER *oper = (QUOTELV_OPER *)Tools_Malloc(sizeof(QUOTELV_OPER));
	
	//初始化请求包头
	oper->HeadAsk.ver = 0x05;
	oper->HeadAsk.language = 0x01;
	
	//初始化分时请求包头
	for(j=0;j<QUOTELV_OPER_MIN_NUM; j++)
	{
		oper->MinAsk[j].fdcount = 8;
		
		for(i=0; i<oper->MinAsk[j].fdcount; i++)		//定制目前所有的分时字段
		{
			oper->MinAsk[j].fd[i] = i+1;
		}
	}
	
	// *2014.12.12 fmy 行情优化
	//初始化报价请求包头
	for(j=0;j<QUOTELV_OPER_PRICE_NUM; j++)
	{
		oper->PriAsk[j].fdcount = 41;
		oper->PriAsk[j].fd[0] = QUOTELV_CUSTOM_CODEINFO;				//股票信息
		oper->PriAsk[j].fd[1] = QUOTELV_CUSTOM_NOW;					//当前价
//		oper->PriAsk[j].fd[2] = QUOTELV_CUSTOM_DR;						//涨跌幅
//		oper->PriAsk[j].fd[3] = QUOTELV_CUSTOM_DIFF;					//涨跌额
		oper->PriAsk[j].fd[2] = QUOTELV_CUSTOM_VOLUME;					//成交量
		oper->PriAsk[j].fd[3] = QUOTELV_CUSTOM_HS;						//换手
		oper->PriAsk[j].fd[4] = QUOTELV_CUSTOM_OPEN;					//开盘
		oper->PriAsk[j].fd[5] = QUOTELV_CUSTOM_HIGH;					//最高
		oper->PriAsk[j].fd[6] = QUOTELV_CUSTOM_LOW;					//最低
		oper->PriAsk[j].fd[7] = QUOTELV_CUSTOM_PRECLOSE;				//昨手
		oper->PriAsk[j].fd[8] = QUOTELV_CUSTOM_AMOUNT;				//金额
		oper->PriAsk[j].fd[9] = QUOTELV_CUSTOM_WB;					//委比
		oper->PriAsk[j].fd[10] = QUOTELV_CUSTOM_WC;					//委差
		oper->PriAsk[j].fd[11] = QUOTELV_CUSTOM_REDV;					//外盘
		oper->PriAsk[j].fd[12] = QUOTELV_CUSTOM_TIME;					//时间
		oper->PriAsk[j].fd[13] = QUOTELV_CUSTOM_AVP;					//均价
		oper->PriAsk[j].fd[14] = QUOTELV_CUSTOM_VR;					//量比
		oper->PriAsk[j].fd[15] = QUOTELV_CUSTOM_SELLP1;				//十档买卖
		oper->PriAsk[j].fd[16] = QUOTELV_CUSTOM_BUYP1;					//十档买卖
		oper->PriAsk[j].fd[17] = QUOTELV_CUSTOM_SELLP2;				//十档买卖
		oper->PriAsk[j].fd[18] = QUOTELV_CUSTOM_BUYP2;					//十档买卖
		oper->PriAsk[j].fd[19] = QUOTELV_CUSTOM_SELLP3;				//十档买卖
		oper->PriAsk[j].fd[20] = QUOTELV_CUSTOM_BUYP3;					//十档买卖
		oper->PriAsk[j].fd[21] = QUOTELV_CUSTOM_SELLP4;				//十档买卖
		oper->PriAsk[j].fd[22] = QUOTELV_CUSTOM_BUYP4;					//十档买卖
		oper->PriAsk[j].fd[23] = QUOTELV_CUSTOM_SELLP5;				//十档买卖
		oper->PriAsk[j].fd[24] = QUOTELV_CUSTOM_BUYP5;					//十档买卖
//		oper->PriAsk[j].fd[27] = QUOTELV_CUSTOM_SELLP6;				//十档买卖
//		oper->PriAsk[j].fd[28] = QUOTELV_CUSTOM_BUYP6;					//十档买卖
//		oper->PriAsk[j].fd[29] = QUOTELV_CUSTOM_SELLP7;				//十档买卖
//		oper->PriAsk[j].fd[30] = QUOTELV_CUSTOM_BUYP7;					//十档买卖
//		oper->PriAsk[j].fd[31] = QUOTELV_CUSTOM_SELLP8;				//十档买卖
//		oper->PriAsk[j].fd[32] = QUOTELV_CUSTOM_BUYP8;					//十档买卖
//		oper->PriAsk[j].fd[33] = QUOTELV_CUSTOM_SELLP9;				//十档买卖
//		oper->PriAsk[j].fd[34] = QUOTELV_CUSTOM_BUYP9;					//十档买卖
//		oper->PriAsk[j].fd[35] = QUOTELV_CUSTOM_SELLP10;				//十档买卖
//		oper->PriAsk[j].fd[36] = QUOTELV_CUSTOM_BUYP10;				//十档买卖
		oper->PriAsk[j].fd[25] = QUOTELV_CUSTOM_SELLV1;				//十档买卖
		oper->PriAsk[j].fd[26] = QUOTELV_CUSTOM_BUYV1;					//十档买卖
		oper->PriAsk[j].fd[27] = QUOTELV_CUSTOM_SELLV2;				//十档买卖
		oper->PriAsk[j].fd[28] = QUOTELV_CUSTOM_BUYV2;					//十档买卖
		oper->PriAsk[j].fd[29] = QUOTELV_CUSTOM_SELLV3;				//十档买卖
		oper->PriAsk[j].fd[30] = QUOTELV_CUSTOM_BUYV3;					//十档买卖
		oper->PriAsk[j].fd[31] = QUOTELV_CUSTOM_SELLV4;				//十档买卖
		oper->PriAsk[j].fd[32] = QUOTELV_CUSTOM_BUYV4;					//十档买卖
		oper->PriAsk[j].fd[33] = QUOTELV_CUSTOM_SELLV5;				//十档买卖
		oper->PriAsk[j].fd[34] = QUOTELV_CUSTOM_BUYV5;					//十档买卖
//		oper->PriAsk[j].fd[47] = QUOTELV_CUSTOM_SELLV6;				//十档买卖
//		oper->PriAsk[j].fd[48] = QUOTELV_CUSTOM_BUYV6;					//十档买卖
//		oper->PriAsk[j].fd[49] = QUOTELV_CUSTOM_SELLV7;				//十档买卖
//		oper->PriAsk[j].fd[50] = QUOTELV_CUSTOM_BUYV7;					//十档买卖
//		oper->PriAsk[j].fd[51] = QUOTELV_CUSTOM_SELLV8;				//十档买卖
//		oper->PriAsk[j].fd[52] = QUOTELV_CUSTOM_BUYV8;					//十档买卖
//		oper->PriAsk[j].fd[53] = QUOTELV_CUSTOM_SELLV9;					//十档买卖
//		oper->PriAsk[j].fd[54] = QUOTELV_CUSTOM_BUYV9;					//十档买卖
//		oper->PriAsk[j].fd[55] = QUOTELV_CUSTOM_SELLV10;					//十档买卖
//		oper->PriAsk[j].fd[56] = QUOTELV_CUSTOM_BUYV10;					//十档买卖
		oper->PriAsk[j].fd[35] = QUOTELV_CUSTOM_CURVOLUME;					//现手
		oper->PriAsk[j].fd[36] = QUOTELV_CUSTOM_PE;					//市盈率
    oper->PriAsk[j].fd[37] = QUOTELV_CUSTOM_SETTLEPRICE;       //结算价
    oper->PriAsk[j].fd[38] = QUOTELV_CUSTOM_PRESETTLEPRICE;    //昨结算价
        oper->PriAsk[j].fd[39] = QUOTELV_RISELIMITPRICE;       //涨停
        oper->PriAsk[j].fd[40] = QUOTELV_DECLIMITPRICE;        //跌停
	}
	
	
	//初始化自选请求包头
	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fdcount = 17;
	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[0] = QUOTELV_CUSTOM_CODEINFO;				//股票信息
	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[1] = QUOTELV_CUSTOM_NOW;					//当前价
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[2] = QUOTELV_CUSTOM_DR;					//涨跌幅
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[3] = QUOTELV_CUSTOM_DIFF;					//涨跌额
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[2] = QUOTELV_CUSTOM_VOLUME;				//成交量
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[3] = QUOTELV_CUSTOM_HS;					//换手
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[4] = QUOTELV_CUSTOM_OPEN;					//开盘
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[5] = QUOTELV_CUSTOM_HIGH;					//最高
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[6] = QUOTELV_CUSTOM_LOW;					//最低
	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[2] = QUOTELV_CUSTOM_PRECLOSE;				//昨收
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[8] = QUOTELV_CUSTOM_WB;					//委比
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[9] = QUOTELV_CUSTOM_PE;					//市盈率
////	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[12] = QUOTELV_CUSTOM_AMP;					//振幅
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[10] = QUOTELV_CUSTOM_AMOUNT;				//金额
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[11] = QUOTELV_CUSTOM_CURVOLUME;			//现手
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[12] = QUOTELV_CUSTOM_VR;					//量比
//  oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[13] = QUOTELV_CUSTOM_SELLP1;      //卖价
//  oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[14] = QUOTELV_CUSTOM_BUYP1;       //买价
//  oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[15] = QUOTELV_CUSTOM_SETTLEPRICE;       //结算价
//  oper->OwnAsk[QUOTELV_OPER_TAG_OWN].fd[16] = QUOTELV_CUSTOM_PRESETTLEPRICE;    //昨结算价
  
//    //初始化全部自选请求包头
//    oper->nOwnAllMaxLen = 10240;
//	oper->OwnAllAsk[QUOTELV_OPER_TAG_OWNALL].fdcount = 2;
//	oper->OwnAllAsk[QUOTELV_OPER_TAG_OWNALL].fd[0] = QUOTELV_CUSTOM_CODEINFO;				//股票信息
//	oper->OwnAllAsk[QUOTELV_OPER_TAG_OWNALL].fd[1] = QUOTELV_CUSTOM_NOW;					//当前价
//	//设置
//    oper->OwnAllAsk[QUOTELV_OPER_TAG_OWNALL].codedata = (char*)Tools_Malloc(oper->nOwnAllMaxLen);
//    oper->OwnAllRes[QUOTELV_OPER_TAG_OWNALL].ownData = (QUOTELV_STOCK_POINT*)Tools_Malloc(sizeof(QUOTELV_STOCK_POINT)*1024);
	
	//初始化okex请求包头
	for(j=0;j<QUOTELV_OPER_INDEX_NUM; j++)
	{
		oper->IndexAsk[j].fdcount = 17;
		oper->IndexAsk[j].fd[0] = QUOTELV_CUSTOM_CODEINFO;				//股票信息
		oper->IndexAsk[j].fd[1] = QUOTELV_CUSTOM_NOW;					//当前价
////		oper->IndexAsk[j].fd[2] = QUOTELV_CUSTOM_DR;					//涨跌幅
////		oper->IndexAsk[j].fd[3] = QUOTELV_CUSTOM_DIFF;					//涨跌额
//		oper->IndexAsk[j].fd[2] = QUOTELV_CUSTOM_VOLUME;				//成交量
//		oper->IndexAsk[j].fd[3] = QUOTELV_CUSTOM_HS;					//换手
//		oper->IndexAsk[j].fd[4] = QUOTELV_CUSTOM_OPEN;					//开盘
//		oper->IndexAsk[j].fd[5] = QUOTELV_CUSTOM_HIGH;					//最高
//		oper->IndexAsk[j].fd[6] = QUOTELV_CUSTOM_LOW;					//最低
		oper->IndexAsk[j].fd[2] = QUOTELV_CUSTOM_PRECLOSE;				//昨收
//		oper->IndexAsk[j].fd[8] = QUOTELV_CUSTOM_WB;					//委比
//		oper->IndexAsk[j].fd[9] = QUOTELV_CUSTOM_PE;					//市盈率
////		oper->IndexAsk[j].fd[12] = QUOTELV_CUSTOM_AMP;					//振幅
//		oper->IndexAsk[j].fd[10] = QUOTELV_CUSTOM_AMOUNT;				//金额
//		oper->IndexAsk[j].fd[11] = QUOTELV_CUSTOM_CURVOLUME;			//现手
//		oper->IndexAsk[j].fd[12] = QUOTELV_CUSTOM_VR;					//量比
//    oper->IndexAsk[j].fd[13] = QUOTELV_CUSTOM_SELLP1;      //卖价
//    oper->IndexAsk[j].fd[14] = QUOTELV_CUSTOM_BUYP1;       //买价
//    oper->IndexAsk[j].fd[15] = QUOTELV_CUSTOM_SETTLEPRICE;       //结算价
//    oper->IndexAsk[j].fd[16] = QUOTELV_CUSTOM_PRESETTLEPRICE;    //昨结算价
	}
	
	
	
	//初始化大盘滚动请求包头
	oper->OwnAsk[QUOTELV_OPER_TAG_OWN_INDEX].fdcount = 3;
	oper->OwnAsk[QUOTELV_OPER_TAG_OWN_INDEX].fd[0] = QUOTELV_CUSTOM_CODEINFO;				//股票信息
	oper->OwnAsk[QUOTELV_OPER_TAG_OWN_INDEX].fd[1] = QUOTELV_CUSTOM_NOW;					//当前价
//	oper->OwnAsk[QUOTELV_OPER_TAG_OWN_INDEX].fd[2] = QUOTELV_CUSTOM_DR;					//涨跌幅
	oper->OwnAsk[QUOTELV_OPER_TAG_OWN_INDEX].fd[2] = QUOTELV_CUSTOM_PRECLOSE;				//昨收
	
	
	//初始化板块请求包头
	for(j=0;j<QUOTELV_OPER_BLOCK_NUM; j++)
	{
		oper->BlockAsk[j].fdcount = 17;
		oper->BlockAsk[j].fd[0] = QUOTELV_CUSTOM_CODEINFO;				//股票信息
		oper->BlockAsk[j].fd[1] = QUOTELV_CUSTOM_NOW;					//当前价
//		oper->BlockAsk[j].fd[2] = QUOTELV_CUSTOM_DR;					//涨跌幅
//		oper->BlockAsk[j].fd[3] = QUOTELV_CUSTOM_DIFF;					//涨跌额
		oper->BlockAsk[j].fd[2] = QUOTELV_CUSTOM_VOLUME;				//成交量
		oper->BlockAsk[j].fd[3] = QUOTELV_CUSTOM_HS;					//换手
		oper->BlockAsk[j].fd[4] = QUOTELV_CUSTOM_OPEN;					//开盘
		oper->BlockAsk[j].fd[5] = QUOTELV_CUSTOM_HIGH;					//最高
		oper->BlockAsk[j].fd[6] = QUOTELV_CUSTOM_LOW;					//最低
		oper->BlockAsk[j].fd[7] = QUOTELV_CUSTOM_PRECLOSE;				//昨手
		oper->BlockAsk[j].fd[8] = QUOTELV_CUSTOM_BLOCKID;				//板块ID
		oper->BlockAsk[j].fd[9] = QUOTELV_CUSTOM_WB;					//委比
		oper->BlockAsk[j].fd[10] = QUOTELV_CUSTOM_PE;					//市盈率
//		oper->BlockAsk[j].fd[16] = QUOTELV_CUSTOM_AMP;					//振幅
		oper->BlockAsk[j].fd[11] = QUOTELV_CUSTOM_AMOUNT;				//金额
		oper->BlockAsk[j].fd[12] = QUOTELV_CUSTOM_CURVOLUME;			//现手
		oper->BlockAsk[j].fd[13] = QUOTELV_CUSTOM_VR;					//量比
    oper->BlockAsk[j].fd[14] = QUOTELV_CUSTOM_SELLP1;      //卖价
    oper->BlockAsk[j].fd[15] = QUOTELV_CUSTOM_BUYP1;       //买价
	}
	
	
	//初始化基金列表
	for(j=0;j<QUOTELV_OPER_DEFAUT_NUM; j++)
	{
		//涨跌幅
		strcpy(oper->FundRes->pRangTag, LOC_UDRANGE);	//用来比较字段
	}
	
	//初始化k线
	oper->nAddedOffset = 60;
	for(j=0;j<QUOTELV_OPER_DEFAUT_NUM; j++)
	{
		oper->KAsk[j].fdcount = 8;
		oper->KAsk[j].fd[0] = QUOTELV_K_CUSTOM_DATE;
		oper->KAsk[j].fd[1] = QUOTELV_K_CUSTOM_OPEN;
		oper->KAsk[j].fd[2] = QUOTELV_K_CUSTOM_HIGH;
		oper->KAsk[j].fd[3] = QUOTELV_K_CUSTOM_LOW;
		oper->KAsk[j].fd[4] = QUOTELV_K_CUSTOM_CUR;
		oper->KAsk[j].fd[5] = QUOTELV_K_CUSTOM_SUM;
		oper->KAsk[j].fd[6] = QUOTELV_K_CUSTOM_VOL;
		oper->KAsk[j].fd[7] = QUOTELV_K_CUSTOM_SWAP;
		oper->KAsk[j].Addedcount = 5;
		oper->KAsk[j].Added[0][0] = QUOTELV_K_CUSTOM_CUR;
		oper->KAsk[j].Added[0][1] = oper->nAddedOffset;
		oper->KAsk[j].Added[1][0] = QUOTELV_K_CUSTOM_HIGH;
		oper->KAsk[j].Added[1][1] = 30;
		oper->KAsk[j].Added[2][0] = QUOTELV_K_CUSTOM_LOW;
		oper->KAsk[j].Added[2][1] = 30;
		oper->KAsk[j].Added[3][0] = QUOTELV_K_CUSTOM_VOL;
		oper->KAsk[j].Added[3][1] = 10;
		oper->KAsk[j].Added[4][0] = QUOTELV_K_CUSTOM_OPEN;
		oper->KAsk[j].Added[4][1] = 30;
	}
	
	//初始化K线指标
	oper->KIndex = QuoteLvKIndex_New();
	
	//初始化最近浏览
	oper->pRecViewArray = NULL;	
	
	
	//初始化其他数据
	oper->nSubscribeId = 1001;			//订阅ID从1001开始
	oper->pSendData = (char *)Tools_Malloc(OPER_SEND_LEN);		//暂定发送的大小不超过
	oper->pSubscribe = QuoteLvSubscribe_New();
	strcpy(oper->pOwnPath,"own.data");
	strcpy(oper->pOwnFundPath,"ownFund.data");
    strcpy(oper->pBDZQPath, "bdzq.data");
    strcpy(oper->pWebSrcPath, "web_version.data");
    strcpy(oper->pRecViewPath, "recView.data");
	
	//========================================================================
	strcpy(oper->pSocketAdd,"");
  
	oper->nSocketPort = 8110;
	oper->nBkCurPage = 0;
    //addfmy
//	oper->nOwnMaxCount = QuoteLvOper_GetOwnCount(oper);
    oper->nOwnMaxCount = 0;
    //addfmy
	oper->nOwnPageCount = 10;
	oper->nOwnCurPage = 0;
	oper->nConType = QUOTELV_CONNECTION_SOCKET;
	oper->nRefTime = 5;
	oper->pQuoteTimer = TimeTools_New();
	//========================================================================
  
  oper->pSocketOper = SocketInterface_NewSocketOper();
  oper->noticeCallBack.pResedData = QuoteLvOper_ResedData;
  oper->noticeCallBack.pCallBack = QuoteLvOper_StockStatusNotice;
  oper->noticeCallBack.pObject = oper;
  SocketInterface_SetStatusNotice(oper->pSocketOper, &(oper->noticeCallBack));
  
  oper->pSocketDictOper = SocketInterface_NewSocketOper();
//  oper->noticeCallBack.pResedData = QuoteLvOper_ResedData;
//  oper->noticeCallBack.pCallBack = QuoteLvOper_StockStatusNotice;
//  oper->noticeCallBack.pObject = oper;
  SocketInterface_SetStatusNotice(oper->pSocketDictOper, &(oper->noticeCallBack));
  
	return oper;
}

void QuoteLvOper_Del(QUOTELV_OPER *aOper)
{
	Tools_Free((void **) &aOper->KIndex);
	QuoteLvSubscribe_Del(aOper->pSubscribe);
	QuoteLvOper_DelAllRecViewCode(aOper->pRecViewArray);
	aOper->pRecViewArray = NULL;
	Tools_Free((void **) &aOper->pRecViewArray);
	
	int i = 0;
	int j = 0;
	
	for(; j<QUOTELV_OPER_INFO_NUM; j++)
	{
		for (; i<aOper->MinInfoRes[j].nTotalCount; i++)
		{
			Tools_Free((void **) &aOper->MinInfoRes[j].infoData[i].pTitle);
			Tools_Free((void **) &aOper->MinInfoRes[j].infoData[i].pDate);
			Tools_Free((void **) &aOper->MinInfoRes[j].infoData[i].pUrl);
		}
	}
	
    Tools_Free(&aOper->OwnAllAsk[QUOTELV_OPER_TAG_OWNALL].codedata);
    Tools_Free(&aOper->OwnAllRes[QUOTELV_OPER_TAG_OWNALL].ownData);
    Tools_Free((void **)&aOper);
}

int  QuoteLvOper_GetDictData(QUOTELV_OPER *aOper,void( *pCallBack )(void *pCBObj, void *p), void *pCBObj)
{
	QUOTELV_DICT_ASK *ask = &aOper->DictAsk;
	QUOTELV_DICT_RES *res = &aOper->DictRes;
	
	char *p = QuoteLvOper_PackHead(aOper,RQS_LV_CODELIST,0,FALSE);
	
	FILE_DATA *data =  DictionaryTools_ReadVerData();
	
	if (data && data->nSize > 0) {
		ask->len = data->nSize;
		
		if (ask->pverdata) {
			Tools_Free((void **)&ask->pverdata);
			ask->pverdata = NULL;
		}
		
		ask->pverdata = (char *) Tools_Malloc(data->nSize + 1);
		memcpy(ask->pverdata,data->pData,data->nSize);
		FileTools_FreeData(data);
	}
	else {
		ask->len = 0;
	}
  
	aOper->HeadAsk.subid = aOper->nSubscribeId++;
	ShortToBytes(ask->len,p);
	p += 2;
	aOper->nSendLen += 2;
	
	if (ask->len > 0) {
		aOper->nSendLen += ask->len;
		memcpy(p,ask->pverdata,ask->len);
	}
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
	//添加到订阅id链表里
	
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void *)ask,(void*)res,aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV_CODELIST);
	
	//QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
  //QuoteLvOper_SendDictData(aOper,aOper->pSendData,aOper->nSendLen);
  
//  //Test
//  strcpy(aOper->pHttpUrl, "http://211.139.150.57:8088/v2cnservice?");//沪港通
//  ///

  //数据字典走http请求
  aOper->nHttpId = HttpTools_GetData(aOper->nHttpId, "http://policyhqyd.51tongcai.com:8088/v2cnservice?", aOper->pSendData, aOper->nSendLen, NULL, QuoteLvOper_HttpNoRefResedData, aOper);
	return 0;
}

int  QuoteLvOper_GetDictData_Manual(QUOTELV_OPER *aOper,void( *pCallBack )(void *pCBObj, void *p), void *pCBObj)
{
  QUOTELV_DICT_ASK *ask = &aOper->DictAsk;
  QUOTELV_DICT_RES *res = &aOper->DictRes;
  
  char *p = QuoteLvOper_PackHead(aOper,RQS_LV_CODELIST,0,FALSE);
  
  FILE_DATA *data =  DictionaryTools_ReadVerData();
  
  if (data && data->nSize > 0) {
    ask->len = data->nSize;
    
    if (ask->pverdata) {
      Tools_Free((void **)&ask->pverdata);
      ask->pverdata = NULL;
    }
    
    ask->pverdata = (char *) Tools_Malloc(data->nSize + 1);
    memcpy(ask->pverdata,data->pData,data->nSize);
    FileTools_FreeData(data);
  }
  else {
    ask->len = 0;
  }
  
  aOper->HeadAsk.subid = aOper->nSubscribeId++;
  ShortToBytes(ask->len,p);
  p += 2;
  aOper->nSendLen += 2;
  
  if (ask->len > 0) {
    aOper->nSendLen += ask->len;
    memcpy(p,ask->pverdata,ask->len);
  }
  
  QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
  IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
  
  //添加到订阅id链表里
  
  QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void *)ask,(void*)res,aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV_CODELIST);
  
  //QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
  //QuoteLvOper_SendDictData(aOper,aOper->pSendData,aOper->nSendLen);
  
  return 0;
}

int  QuoteLvOper_GetMinData(QUOTELV_OPER *aOper,void( *pCallBack )(void *pCBObj, void *p), void *pCBObj,char aType, char* aCode, char aId, int aSubscribeId, TBOOL aIsSubscribe, int aIndex, int aDate,int aNum, int aArrayIndex)
{
	if(aCode == NULL)
	{
		return 0;
	}
	
	QUOTELV_MIN_ASK *ask = &aOper->MinAsk[aArrayIndex];
	QUOTELV_MIN_RES *res = &aOper->MinRes[aArrayIndex];
	//res->nTotalCount = 0;
  res->bLeve2Status = FALSE;
	
	char *p = QuoteLvOper_PackHead(aOper,aType,aSubscribeId,aIsSubscribe);
	
	if (aType == RQS_LV_MIN)
	{
		aOper->HeadAsk.subid = aOper->nSubscribeId++; 
		memset(ask->code,0,7);
		strcpy(ask->code,aCode);
		ask->marketid = aId;
		ask->index = aIndex;
		aOper->nSendLen += 10 + ask->fdcount;
		memcpy(p,ask->code,6);
		p += 6;
		p[0] = ask->marketid;
		p += 1;
		ShortToBytes(ask->index,p);
		p += 2;	
		p[0] = ask->fdcount;
		p += 1;
		
		for(int i=0; i<ask->fdcount; i++)
		{
			p[0] = ask->fd[i];
			p += 1;
		}
		
	}
	else if(aType == RQS_LV_DFTMIN)
	{
		aOper->HeadAsk.subid = aOper->nSubscribeId++;
		memset(ask->code,0,7);
		strcpy(ask->code,aCode);
		ask->marketid = aId;
		ask->index = aIndex;
		aOper->nSendLen += 9;
		memcpy(p,ask->code,6);
		p += 6;
		p[0] = ask->marketid;
		p += 1;
		ShortToBytes(ask->index,p);
		p += 2;
	}
	else if(aType == RQS_LV_HISMIN)
	{
		aOper->HeadAsk.subid = 0;
		memset(ask->code,0,7);
		strcpy(ask->code,aCode);
		ask->marketid = aId;
		ask->date = aDate;
		ask->count = aNum;
		aOper->nSendLen += 17 + 2*ask->fdcount;
		memcpy(p,ask->code,6);
		p += 6;
		p[0] = ask->marketid;
		p += 1;
		IntToBytes(ask->date,p);
		p += 4;
		IntToBytes(ask->count,p);
		p += 4;
		p[0] = ask->fdcount;
		p += 1;
		
		for(int i=0; i<ask->fdcount; i++)
		{
			ShortToBytes(ask->fd[i],p);
			p += 2;
		}
		
		aOper->HeadAsk.subid = QUOTELV_SUBSCRIBE_ID_HISMIN;
	}
	//add by jason 存储订阅ID
	res->nSubID = aOper->HeadAsk.subid;
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
  //增加保存文件
  int success = QuoteLvOper_AddRecView(aOper, aCode,aId);
  
	//添加到最近浏览
//	aOper->pRecViewArray = QuoteLvOper_AddRecViewCode(aOper->pRecViewArray,aCode,aId);
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void *)ask,(void*)res,aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,aType);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

////lisz add 20110916 start
//int  QuoteLvOper_GetLeve2MinData(QUOTELV_OPER *aOper,
//                                 void( *pCallBack )(void *pCBObj, void *p),
//                                 void *pCBObj,
//                                 char aType,
//                                 char* aCode,
//                                 char aId,
//                                 int aSubscribeId,
//                                 TBOOL aIsSubscribe,
//                                 int aIndex,
//                                 int aDate,int
//                                 aNum,
//                                 int aArrayIndex)
//{
//  if(aCode == NULL)
//	{
//		return 0;
//	}
//	
//	QUOTELV_LEVE2_MIN_ASK *ask = &aOper->Leve2MinAsk[aArrayIndex];
//	QUOTELV_MIN_RES *res = &aOper->MinRes[aArrayIndex];
//  
//  res->bLeve2Status = TRUE;
//	
//	char *p = QuoteLvOper_PackHead(aOper,aType,aSubscribeId,aIsSubscribe);
//	
//	if (aType == RQS_LEVEL2_MIN_TRANC)
//	{
//		aOper->HeadAsk.subid = aOper->nSubscribeId++; 
//		memset(ask->code,0,7);
//		strcpy(ask->code,aCode);
//		ask->marketid = aId;
//		ask->index = aIndex;
//		aOper->nSendLen += 10 + ask->fdcount;
//		memcpy(p,ask->code,6);
//		p += 6;
//		p[0] = ask->marketid;
//		p += 1;
//		ShortToBytes(ask->index,p);
//		p += 2;	
//		p[0] = ask->fdcount;
//		p += 1;
//		
//		for(int i=0; i<ask->fdcount; i++)
//		{
//			p[0] = ask->fd[i];
//			p += 1;
//		}
//		
//	}
//	//add by jason 存储订阅ID
//	res->nSubID = aOper->HeadAsk.subid;
//	
//	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
//	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
//	
//	//添加到订阅id链表里
//	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void *)ask,(void*)res,aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,aType);
//	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
//	return aOper->HeadAsk.subid;
//}
////lisz add 20110916 end

int  QuoteLvOper_GetDetailData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, char aType, char* aCode, char aId, int aIndex, short aPageCount, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	if(aCode == NULL)
	{
		return 0;
	}
	
	char * p = QuoteLvOper_PackHead(aOper,aType,aSubscribeId,aIsSubscribe);
	
	QUOTELV_DETAIL_ASK *ask = &aOper->DetailAsk[aArrayIndex];
	QUOTELV_DETAIL_RES *res = &aOper->DetailRes[aArrayIndex];
	res->nZTotalCount = -1;
	//add by jason 记录订阅id
	res->nSubID = aOper->HeadAsk.subid;
	//end
	
	memset(ask->code,0,7);
	strcpy(ask->code,aCode);
	ask->marketid = aId;
	ask->index = aIndex;
	ask->count = aPageCount;
	aOper->nSendLen += 13;
	memcpy(p,ask->code,6);
	p += 6;
	p[0] = ask->marketid;
	p += 1;
	IntToBytes(ask->index,p);
	p += 4;
	ShortToBytes(ask->count,p);
	p += 2;
	
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
	
	//添加到最近浏览
	aOper->pRecViewArray = QuoteLvOper_AddRecViewCode(aOper->pRecViewArray,aCode,aId);
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void *)ask, (void*)res,aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,aType);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetIndividData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, char* aCode, char aId, int aIndex, short aPageCount, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	if(aCode == NULL)
	{
		return 0;
	}
	
	char * p = QuoteLvOper_PackHead(aOper,RQS_LV2_LSTNTICK,aSubscribeId,aIsSubscribe);
	
	QUOTELV_INDIVID_ASK *ask = &aOper->IndividAsk[aArrayIndex];
	QUOTELV_INDIVID_RES *res = &aOper->IndividRes[aArrayIndex];
	
	memset(ask->code,0,7);
	strcpy(ask->code,aCode);
	ask->marketid = aId;
	ask->index = aIndex;
	ask->count = aPageCount;
	aOper->nSendLen += 13;
	memcpy(p,ask->code,6);
	p += 6;
	p[0] = ask->marketid;
	p += 1;
	IntToBytes(ask->index,p);
	p += 4;
	ShortToBytes(ask->count,p);
	p += 2;
	
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
	
	//添加到最近浏览
	aOper->pRecViewArray = QuoteLvOper_AddRecViewCode(aOper->pRecViewArray,aCode,aId);
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV2_LSTNTICK);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetIndividVolData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, char* aCode, char aId, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	if(aCode == NULL)
	{
		return 0;
	}
	
	char * p = QuoteLvOper_PackHead(aOper,RQS_LV2_INDVOL,aSubscribeId,aIsSubscribe);
	
	QUOTELV_INDIVID_VOL_ASK *ask = &aOper->IndividVolAsk[aArrayIndex];
	QUOTELV_INDIVID_VOL_RES *res = &aOper->IndividVolRes[aArrayIndex];
	
	memset(ask->code,0,7);
	strcpy(ask->code,aCode);
	ask->marketid = aId;
	aOper->nSendLen += 7;
	memcpy(p,ask->code,6);
	p += 6;
	p[0] = ask->marketid;
	p += 1;
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
	//添加到最近浏览
	aOper->pRecViewArray = QuoteLvOper_AddRecViewCode(aOper->pRecViewArray,aCode,aId);
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV2_INDVOL);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetExdiviKData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj,int aKLineType, char* aCode, char aId,int aExdiviType, int aDate, int aIndex, int aPageCount, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
    if(aCode == NULL)
    {
      return 0;
    }
    char * p = QuoteLvOper_PackHead(aOper,RSQ_LV_RQS_EXDIVIKLINE,aSubscribeId,aIsSubscribe);
    
    QUOTELV_K_ASK *ask = &aOper->KAsk[aArrayIndex];
    QUOTELV_K_RES *res = &aOper->KRes[aArrayIndex];
    res->nNewTime = -1;
    
    res->bLeve2DDXStatus = FALSE;
    res->bLeve2TrancStatus = FALSE;
    res->nEffectiveCount = 0;
    res->nTrancEffectiveCount = 0;
    
    
    memset(ask->code,0,7);
    strcpy(ask->code,aCode);
    ask->marketid = aId;
    ask->exdiviType = aExdiviType;
    ask->date = aDate;
    ask->page = aIndex;
    ask->klinetype = aKLineType;
    
    ask->count = aPageCount;
    
    aOper->nSendLen += 19 + 2*ask->Addedcount + 2*ask->fdcount;
    memcpy(p,ask->code,6);
    p += 6;
    p[0] = ask->marketid;
    p += 1;
    p[0] = ask->exdiviType;
    p += 1;
    p[0] = ask->klinetype;
    p += 1;
    IntToBytes(ask->date,p);
    p += 4;
    ShortToBytes(ask->page,p);
    p += 2;
    ShortToBytes(ask->count,p);
    p += 2;
    
    p[0] = ask->fdcount;
    p += 1;
    
    for(int i=0; i<ask->fdcount; i++)
    {
      p[0] = ask->fd[i];
      p += 1;
    }
    
    p[0] = ask->Addedcount;
    p += 1;
    
    for(int i=0; i<ask->fdcount; i++)
    {
      p[0] = ask->Added[i][0];
      p += 1;
      p[0] = ask->Added[i][1];
      p += 1;
    }
    
    QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
    IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
    //添加到最近浏览
    aOper->pRecViewArray = QuoteLvOper_AddRecViewCode(aOper->pRecViewArray,aCode,aId);
    //添加到订阅id链表里
    QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RSQ_LV_RQS_EXDIVIKLINE);
    QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
    return aOper->HeadAsk.subid;
}
  
int  QuoteLvOper_GetKData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj,int aKLineType, char* aCode, char aId, int aDate, int aIndex, int aPageCount, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	if(aCode == NULL)
	{
		return 0;
	}
	char * p = QuoteLvOper_PackHead(aOper,RQS_LV_KLINE,aSubscribeId,aIsSubscribe);
	
	QUOTELV_K_ASK *ask = &aOper->KAsk[aArrayIndex];
	QUOTELV_K_RES *res = &aOper->KRes[aArrayIndex];
	res->nNewTime = -1;
  
  res->bLeve2DDXStatus = FALSE;
  res->bLeve2TrancStatus = FALSE;
	res->nEffectiveCount = 0;
	res->nTrancEffectiveCount = 0;
  
	
	memset(ask->code,0,7);
	strcpy(ask->code,aCode);
	ask->marketid = aId;
	ask->date = aDate;
	ask->page = aIndex;
	ask->klinetype = aKLineType;
	
	ask->count = aPageCount;
	
	aOper->nSendLen += 18 + 2*ask->Addedcount + ask->fdcount;
	memcpy(p,ask->code,6);
	p += 6;
	p[0] = ask->marketid;
	p += 1;
	p[0] = ask->klinetype;
	p += 1;
	IntToBytes(ask->date,p);
	p += 4;
	ShortToBytes(ask->page,p);
	p += 2;
	ShortToBytes(ask->count,p);
	p += 2;
	
	p[0] = ask->fdcount;
	p += 1;
	
	for(int i=0; i<ask->fdcount; i++)
	{
		p[0] = ask->fd[i];
		p += 1;
	}
	
	p[0] = ask->Addedcount;
	p += 1;
	
	for(int i=0; i<ask->fdcount; i++)
	{
		p[0] = ask->Added[i][0];
		p += 1;
		p[0] = ask->Added[i][1];
		p += 1;
	}
	
	
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
  //添加到最近浏览
	aOper->pRecViewArray = QuoteLvOper_AddRecViewCode(aOper->pRecViewArray,aCode,aId);
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV_KLINE);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetLeve2KData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj,int aKLineType, char* aCode, char aId, int aDate, int aIndex, int aPageCount, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	if(aCode == NULL)
	{
		return 0;
	}
	char * p = QuoteLvOper_PackHead(aOper,RQS_LEVEL2_TRANS_ORDER,aSubscribeId,aIsSubscribe);
	
	QUOTELV_LEVE2_K_ASK *ask = &aOper->Leve2KAsk[aArrayIndex];
	QUOTELV_K_RES *res = &aOper->KRes[aArrayIndex];
	//res->nNewTime = -1;
  
  res->bLeve2DDXStatus = TRUE;
	
	memset(ask->code,0,7);
	strcpy(ask->code,aCode);
	ask->marketid = aId;
	ask->date = aDate;
	ask->page = aIndex;
	ask->klinetype = aKLineType;
	
	ask->count = aPageCount;
	
	aOper->nSendLen += 18 + 2*ask->Addedcount + ask->fdcount;
	memcpy(p,ask->code,6);
	p += 6;
	p[0] = ask->marketid;
	p += 1;
	p[0] = ask->klinetype;
	p += 1;
	IntToBytes(ask->date,p);
	p += 4;
	ShortToBytes(ask->page,p);
	p += 2;
	ShortToBytes(ask->count,p);
	p += 2;
	
	p[0] = ask->fdcount;
	p += 1;
	
	for(int i=0; i<ask->fdcount; i++)
	{
		p[0] = ask->fd[i];
		p += 1;
	}
	
	p[0] = ask->Addedcount;
	p += 1;
	
	for(int i=0; i<ask->fdcount; i++)
	{
		p[0] = ask->Added[i][0];
		p += 1;
		p[0] = ask->Added[i][1];
		p += 1;
	}
	
	
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
  //  //添加到最近浏览
  //	aOper->pRecViewArray = QuoteLvOper_AddRecViewCode(aOper->pRecViewArray,aCode,aId);
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LEVEL2_TRANS_ORDER);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetLeve2TrancKData(QUOTELV_OPER *aOper,
                                    void( *pCallBack )(void *pCBObj, void *p),
                                    void *pCBObj,
                                    int aKLineType,
                                    char* aCode,
                                    char aId,
                                    int aDate,
                                    int aIndex,
                                    int aPageCount,
                                    int aSubscribeId,
                                    TBOOL aIsSubscribe,
                                    int aArrayIndex)
{
  if(aCode == NULL)
	{
		return 0;
	}
	char * p = QuoteLvOper_PackHead(aOper,RQS_LEVEL2_TRANS_TRANC,aSubscribeId,aIsSubscribe);
	
	QUOTELV_LEVE2_TRANC_K_ASK *ask = &aOper->Leve2TrancKAsk[aArrayIndex];
	QUOTELV_K_RES *res = &aOper->KRes[aArrayIndex];
	//res->nNewTime = -1;
  
  res->bLeve2TrancStatus = TRUE;
	
	memset(ask->code,0,7);
	strcpy(ask->code,aCode);
	ask->marketid = aId;
	ask->date = aDate;
	ask->page = aIndex;
	ask->klinetype = aKLineType;
	
	ask->count = aPageCount;
	
	aOper->nSendLen += 18 + 2*ask->Addedcount + ask->fdcount;
	memcpy(p,ask->code,6);
	p += 6;
	p[0] = ask->marketid;
	p += 1;
	p[0] = ask->klinetype;
	p += 1;
	IntToBytes(ask->date,p);
	p += 4;
	ShortToBytes(ask->page,p);
	p += 2;
	ShortToBytes(ask->count,p);
	p += 2;
	
	p[0] = ask->fdcount;
	p += 1;
	
	for(int i=0; i<ask->fdcount; i++)
	{
		p[0] = ask->fd[i];
		p += 1;
	}
	
	p[0] = ask->Addedcount;
	p += 1;
	
	for(int i=0; i<ask->fdcount; i++)
	{
		p[0] = ask->Added[i][0];
		p += 1;
		p[0] = ask->Added[i][1];
		p += 1;
	}
	
	
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
  //  //添加到最近浏览
  //	aOper->pRecViewArray = QuoteLvOper_AddRecViewCode(aOper->pRecViewArray,aCode,aId);
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LEVEL2_TRANS_TRANC);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetPriceData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, char* aCode, char aId, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	if(aCode == NULL)
	{
		return 0;
	}
	
	char * p = QuoteLvOper_PackHead(aOper,RQS_LV_GGRT,aSubscribeId,aIsSubscribe);
	
	QUOTELV_PRICE_ASK *ask = &aOper->PriAsk[aArrayIndex];
	QUOTELV_PRICE_RES *res = &aOper->PriRes[aArrayIndex];
	
	memset(ask->code,0,7);
	strcpy(ask->code,aCode);
	ask->marketid = aId;
	
	aOper->nSendLen += 9 + 2 * ask->fdcount;
	memcpy(p,ask->code,6);
	p += 6;
	p[0] = ask->marketid;
	p += 1;
	ShortToBytes(ask->fdcount,p);
	p += 2;
	
	for(int i=0; i<ask->fdcount; i++)	
	{
		ShortToBytes(ask->fd[i],p);
		p += 2;
	}
	
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	//添加到最近浏览
	aOper->pRecViewArray = QuoteLvOper_AddRecViewCode(aOper->pRecViewArray,aCode,aId);
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV_GGRT);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetOwnData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, int aIndex, short aPageCount, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	char * p = QuoteLvOper_PackHead(aOper,RQS_LV_ZXGRT,aSubscribeId,aIsSubscribe);
	
	QUOTELV_OWN_ASK *ask = &aOper->OwnAsk[aArrayIndex];
	QUOTELV_OWN_RES *res = &aOper->OwnRes[aArrayIndex];
	
	
	memset(ask->codedata,0,MAX_PATH);
	ask->count = QuoteLvOper_GetByte(aOper,ask->codedata,aIndex,aPageCount);
	
	if (ask->count < 0)			//如果小于0，请求的页码不对
	{
		return 0;
	}
	
	aOper->nOwnCurPage = aIndex/aPageCount;
	if (aIndex%aPageCount>0) {
		aOper->nOwnCurPage++;
	}
	
	aOper->nSendLen += 4 + 7 * ask->count + 2 * ask->fdcount;
	
	ShortToBytes(ask->count,p);
	p += 2;
	
	memcpy(p,ask->codedata,7*ask->count);
	p += 7*ask->count;
	
	ShortToBytes(ask->fdcount,p);
	p += 2;
	
	for(int i=0; i<ask->fdcount; i++)	
	{
		ShortToBytes(ask->fd[i],p);
		p += 2;
	}
	
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV_ZXGRT);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetOwnAllData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
    char * p = QuoteLvOper_PackHead(aOper,RQS_LV_ZXGRT,aSubscribeId,aIsSubscribe);
	
	QUOTELV_OWNALL_ASK *ask = &aOper->OwnAllAsk[aArrayIndex];
	QUOTELV_OWNALL_RES *res = &aOper->OwnAllRes[aArrayIndex];
	
	
	memset(ask->codedata,0,MAX_PATH);
	ask->count = QuoteLvOper_GetOwnCount(aOper);
    if(ask->count * 7 > aOper->nOwnAllMaxLen){
        aOper->nOwnAllMaxLen = ask->count * 7;
        Tools_Free(&ask->codedata);
        ask->codedata = (char*) Tools_Malloc(aOper->nOwnAllMaxLen);
    }
    
    char *all = QuoteLvOper_GetAllOwnCode(aOper);
    memcpy(ask->codedata, all+4, ask->count * 7);
	
	if (ask->count == 0)			//如果小于0，请求的页码不对
	{
		return 0;
	}
	
	aOper->nSendLen += 4 + 7 * ask->count + 2 * ask->fdcount;
	
	ShortToBytes(ask->count,p);
	p += 2;
	
	memcpy(p,ask->codedata,7*ask->count);
	p += 7*ask->count;
	
	ShortToBytes(ask->fdcount,p);
	p += 2;
	
	for(int i=0; i<ask->fdcount; i++)	
	{
		ShortToBytes(ask->fd[i],p);
		p += 2;
	}
	
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV_ZXGRT);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetIndexOwnData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	char * p = QuoteLvOper_PackHead(aOper,RQS_LV_ZXGRT,aSubscribeId,aIsSubscribe);
	
	QUOTELV_OWN_ASK *ask = &aOper->OwnAsk[aArrayIndex];
	QUOTELV_OWN_RES *res = &aOper->OwnRes[aArrayIndex];
	
	aOper->nSendLen += 18 + 2 * ask->fdcount;
	
	ask->count = 2;
	
	memset(ask->codedata,0,MAX_PATH);
	memcpy(ask->codedata,"1A000113990012",14);
	
	ask->codedata[6] = 0x01;
	ask->codedata[13] = 0x02;
	
	ShortToBytes(ask->count,p);
	p += 2;
	
	memcpy(p,ask->codedata,7*ask->count);
	p += 7*ask->count;
	
	ShortToBytes(ask->fdcount,p);
	p += 2;
	
	for(int i=0; i<ask->fdcount; i++)	
	{
		ShortToBytes(ask->fd[i],p);
		p += 2;
	}
	
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV_ZXGRT);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetIndexData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, char aType, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	char * p = QuoteLvOper_PackHead(aOper,aType,aSubscribeId,aIsSubscribe);
	
	QUOTELV_INDEX_ASK *ask = &aOper->IndexAsk[aArrayIndex];
	QUOTELV_INDEX_RES *res = &aOper->IndexRes[aArrayIndex];
	
	aOper->nSendLen += 2 + 2 * ask->fdcount;
	ShortToBytes(ask->fdcount,p);
	p += 2;
	
	for(int i=0; i<ask->fdcount; i++)	
	{
		ShortToBytes(ask->fd[i],p);
		p += 2;
	}
	
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,aType);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetTrustData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, char* aCode, char aId, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	char * p = QuoteLvOper_PackHead(aOper,RQS_LV2_BSQUEUE,aSubscribeId,aIsSubscribe);
	
	QUOTELV_TRUST_ASK *ask = &aOper->TrustAsk[aArrayIndex];
	QUOTELV_TRUST_RES *res = &aOper->TrustRes[aArrayIndex];
	
	aOper->nSendLen += 7;
	memset(ask->code,0,7);
	strcpy(ask->code,aCode);
	ask->marketid = aId;
	memcpy(p,ask->code,6);
	p += 6;
	p[0] = ask->marketid;
	p += 1;
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度

	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV2_BSQUEUE);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetBlockData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, int aType, long64 aBlockId, int aIndex, short aSort, char aMode, int aSubscribeId, TBOOL aIsSubscribe, short nPageCount, int aArrayIndex)
{
	char * p = QuoteLvOper_PackHead(aOper,aType,aSubscribeId,aIsSubscribe);
	
	QUOTELV_BLOCK_ASK *ask = &aOper->BlockAsk[aArrayIndex];
	QUOTELV_BLOCK_RES *res = &aOper->BlockRes[aArrayIndex];
	
	
	if(nPageCount == -1)
	{
		ask->count = aOper->nBkPageCount;
	}
	else
	{
		ask->count = nPageCount;
	}
	
	ask->blockid = aBlockId;
	ask->index = aIndex;
	ask->sortindex = aSort;
	ask->sortmode = aMode;
	
	
	if (aType == RQS_LV_BOARDRANK)
	{
		aOper->nSendLen += 19 + 2 * ask->fdcount;
		Long64ToBytes(ask->blockid,p);
		p += 8;
		IntToBytes(ask->index,p);
		p += 4;
	}
	else
	{
		aOper->nSendLen += 11 + 2 * ask->fdcount;
		ShortToBytes(ask->blockid,p);
		p += 2;
		ShortToBytes(ask->index,p);
		p += 2;
	}
	
	
	ShortToBytes(ask->count,p);
	p += 2;
	ShortToBytes(ask->sortindex,p);
	p += 2;
	p[0] = ask->sortmode;
	p += 1;
	ShortToBytes(ask->fdcount,p);
	p += 2;
	
	for(int i=0; i<ask->fdcount; i++)	
	{
		ShortToBytes(ask->fd[i],p);
		p += 2;
	}
	
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
		//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,aType);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetSelStockData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, long64 aBlockId,  short aSelType, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	
	char * p = QuoteLvOper_PackHead(aOper,RQS_LV2_DATASELSTOCK,aSubscribeId,aIsSubscribe);
	
	QUOTELV_SEL_STOCK_ASK *ask = &aOper->SelAsk[aArrayIndex];
	QUOTELV_SEL_STOCK_RES *res = &aOper->SelRes[aArrayIndex];
	
	aOper->nSendLen += 10;
	
	ask->blockid = aBlockId;
	ask->type = aSelType;
	
	Long64ToBytes(ask->blockid,p);
	p += 8;
	ShortToBytes(ask->type,p);
	p += 2;

	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV2_DATASELSTOCK);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetSelDirListData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj,  short aDirid, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{

	char * p = QuoteLvOper_PackHead(aOper,RQS_LV2_DATASELDIRLIST,aSubscribeId,aIsSubscribe);
  
	QUOTELV_SEL_DIRLIST_ASK *ask = &aOper->SelDirListAsk[aArrayIndex];
	QUOTELV_SEL_DIRLIST_RES *res = &aOper->SelDirListRes[aArrayIndex];

	aOper->nSendLen += 2;

	ask->dirid = aDirid;
  
	ShortToBytes(ask->dirid,p);
	p += 2;

	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV2_DATASELDIRLIST);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}


int  QuoteLvOper_GetMinInfoData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, char* aCode, char aId, int aInfoType, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	char * p = QuoteLvOper_PackHead(aOper,RQS_LV_RELINFO,aSubscribeId,aIsSubscribe);
	
	QUOTELV_STOCKINFO_ASK *ask = &aOper->MinInfoAsk[aArrayIndex];
	QUOTELV_STOCKINFO_RES *res = &aOper->MinInfoRes[aArrayIndex];
	
	aOper->nSendLen += 17;
	memset(ask->code,0,7);
	strcpy(ask->code,aCode);
	ask->marketid = aId;
	ask->type = aInfoType;
	memcpy(p,ask->code,6);
	p += 6;
	p[0] = ask->marketid;
	p += 1;
	
	p[0] = ask->type;
	p += 1;
	
	Long64ToBytes(ask->time,p);
	p += 8;
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
	//添加到最近浏览
	aOper->pRecViewArray = QuoteLvOper_AddRecViewCode(aOper->pRecViewArray,aCode,aId);
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV_RELINFO);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
  
	return aOper->HeadAsk.subid;
}

int  QuoteLvOper_GetFundListData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, char *aUrl, int aSubscribeId, int aArrayIndex)
{
	
	if (aUrl == NULL)
	{
		return 0;
	}
	
	QUOTELV_FUND_ASK *ask = &aOper->FundAsk[aArrayIndex];
	QUOTELV_FUND_RES *res = &aOper->FundRes[aArrayIndex];
	
	ask->nArrayIndex = aArrayIndex;
	
    int nHttpId = 0;

	if(strlen(aUrl) < 256)
	{
		nHttpId = HttpTools_GetData(0,aUrl,NULL,0,"application/x-www-form-urlencoded",QuoteLvOper_ResedFundData,aOper);
	}else {
		char s[256];
		memset(s, 0, 256);
		char *p = strstr(aUrl, "?");
		
		if (p) {
			memcpy(s, aUrl, p-aUrl+1);
			int nLen = strlen(aUrl);
			char *body = (char*) Tools_Malloc(nLen);
			nLen = strlen(p+1);
			strcpy(body, p+1);
			nHttpId = HttpTools_GetData(0,s,body,nLen,"application/x-www-form-urlencoded",QuoteLvOper_ResedFundData,aOper);
			Tools_Free(&body);
		}
		else {
			nHttpId = HttpTools_GetData(0,aUrl,NULL,0,"application/x-www-form-urlencoded",QuoteLvOper_ResedFundData,aOper);
		}
		
	}
	
	//添加到订阅id链表里
	
	if (aSubscribeId == 0)
	{
		aOper->HeadAsk.subid = aOper->nSubscribeId++; 
		QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void *)ask, (void *)res,"FundList",8,aOper->HeadAsk.subid,nHttpId,0);
	}
	else
	{
		QUOTELV_SUBSCRIBE_ITEM *pItem = QuoteLvSubscribe_GetItem(aOper->pSubscribe,aSubscribeId);
		
		if (pItem)
		{
			pItem->HttpId = nHttpId;
			aOper->HeadAsk.subid = pItem->Id;
		}
		
	}

	return aOper->HeadAsk.subid;
	
}

int  QuoteLvOper_GetFundOwnData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, char *aUrl, char* aData, int aLen, int aSubscribeId, int aArrayIndex)
{
	if (aUrl == NULL || aLen == 0 || aData == NULL)
	{
		return 0;
	}
	
	QUOTELV_FUND_ASK *ask = &aOper->FundAsk[aArrayIndex];
	QUOTELV_FUND_RES *res = &aOper->FundRes[aArrayIndex];
	
	ask->nArrayIndex = aArrayIndex;
	
	int nHttpId = HttpTools_GetData(0,aUrl,aData,aLen,"application/x-www-form-urlencoded",QuoteLvOper_ResedFundData,aOper);
	
	//添加到订阅id链表里
	
	if (aSubscribeId == 0)
	{
		aOper->HeadAsk.subid = aOper->nSubscribeId++; 
		QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void *)ask, (void *)res,"FundList",8,aOper->HeadAsk.subid,nHttpId,0);
	}
	else
	{
		QUOTELV_SUBSCRIBE_ITEM *pItem = QuoteLvSubscribe_GetItem(aOper->pSubscribe,aSubscribeId);
		
		if (pItem)
		{
			pItem->HttpId = nHttpId;
			aOper->HeadAsk.subid = pItem->Id;
		}
		
	}
	
	return aOper->HeadAsk.subid;
}

int QuoteLvOper_GetFundValueChart(QUOTELV_OPER *aOper,void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, char *aUrl, char* aCode, char aMarket, int aSubscribeId, int aArrayIndex,char *aMobile)
{	
	if (aUrl == NULL)
	{
		return 0;
	}
	
	QUOTELV_FUND_MIN_RES *res = &aOper->FundMinRes[aArrayIndex];
	
	char head[22];
	memset(head, 0, sizeof(head));
	head[0] = 0x01;			//全包
	head[19] = 0x02;		//版本号
	head[20] = 0x39;		//功能号
	head[21] = 0x01;		//简体中文
	char *p;
	memset(aOper->pSendData, 0, OPER_SEND_LEN);
	p = aOper->pSendData;
	//数据包
	p[4] = 0x01;
	//行情包
	p[5] = 0x01;
	
	p+=6;
	//打包头
	memcpy(p, head, 22);
	p+=22;
	
	//打包体
	char pTemp[7];
	memset(pTemp, 0, 7);
	strcpy(pTemp, aCode);
	//股票代码
	memcpy(p, pTemp, 6);
	p+=6;
	//市场ID
	p[0] = aMarket;
	p+=1;
	
	//起始位置
	ShortToBytes(0, p);
	p+=2;
	//请求个数
	ShortToBytes(100, p);
	p+=2;
  //手机号
  memcpy(p, aMobile, 11);
  p+=11;
	
	//打长度
	IntToBytes(((p-aOper->pSendData)-5), aOper->pSendData);
	
	int nHttpId = HttpTools_GetData(0, aUrl, aOper->pSendData, (p-aOper->pSendData), "application/x-www-form-urlencoded", QuoteLvOper_ResedFundVauleData, aOper);
	
	//添加到订阅id链表里
	
	if (aSubscribeId == 0)
	{
		aOper->HeadAsk.subid = aOper->nSubscribeId++; 
		QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,NULL, (void *)res,"FundValue",9,aOper->HeadAsk.subid,nHttpId,0);
	}
	else
	{
		QUOTELV_SUBSCRIBE_ITEM *pItem = QuoteLvSubscribe_GetItem(aOper->pSubscribe,aSubscribeId);
		
		if (pItem)
		{
			pItem->HttpId = nHttpId;
			aOper->HeadAsk.subid = pItem->Id;
		}
		
	}
	
	return aOper->HeadAsk.subid;
}

int QuoteLvOper_GetFundInfoData(QUOTELV_OPER *aOper,void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, char *aUrl, char* aCode, char aMarket, int aSubscribeId, int aArrayIndex)
{
	if (aUrl == NULL)
	{
		return 0;
	}
	
	char *p = QuoteLvOper_PackHead(aOper,RQS_LV_RELINFO,aSubscribeId,TRUE);
	
	QUOTELV_STOCKINFO_ASK *ask = &aOper->MinInfoAsk[aArrayIndex];
	QUOTELV_STOCKINFO_RES *res = &aOper->MinInfoRes[aArrayIndex];
	
	aOper->nSendLen += 17;
	memset(ask->code,0,7);
	strcpy(ask->code,aCode);
	ask->marketid = aMarket;
	ask->type = 3;
	memcpy(p,ask->code,6);
	p += 6;
	p[0] = ask->marketid;
	p += 1;
	
	p[0] = ask->type;
	p += 1;
	
	Long64ToBytes(ask->time,p);
	p += 8;
	
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
		
	int nHttpId = HttpTools_GetData(0, aUrl, aOper->pSendData, (p-aOper->pSendData), "application/x-www-form-urlencoded", QuoteLvOper_ResedFundInfoData, aOper);
	
	//添加到订阅id链表里
	
	if (aSubscribeId == 0)
	{
		aOper->HeadAsk.subid = aOper->nSubscribeId++; 
		QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,NULL, (void *)res,"FundInfo",8,aOper->HeadAsk.subid,nHttpId,0);
	}
	else
	{
		QUOTELV_SUBSCRIBE_ITEM *pItem = QuoteLvSubscribe_GetItem(aOper->pSubscribe,aSubscribeId);
		
		if (pItem)
		{
			pItem->HttpId = nHttpId;
			aOper->HeadAsk.subid = pItem->Id;
		}
		
	}
	
	return aOper->HeadAsk.subid;
}


int  QuoteLvOper_GetCancelTrustData(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj, char aTrustType, char* aCode, char aId, int aIndex, short aPageCount, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{

	char * p = QuoteLvOper_PackHead(aOper,RQS_LV2_CANCQUEUE,aSubscribeId,aIsSubscribe);

	QUOTELV_CANCELTRUST_ASK *ask = &aOper->CancelTrustAsk[aArrayIndex];
	QUOTELV_CANCELTRUST_RES *res = &aOper->CancelTrustRes[aArrayIndex];
	res->nZTotalCount = 0;

	ask->type = aTrustType;
	ask->index = aIndex;
	strcpy(ask->code,aCode);
	ask->marketid = aId;
	ask->count = aPageCount;

	aOper->nSendLen += 14;
	p[0] = ask->type;
	p += 1;
	memcpy(p,ask->code,6);
	p += 6;
	p[0] = ask->marketid;
	p += 1;
	IntToBytes(ask->index,p);
	p += 4;
	ShortToBytes(ask->count,p);
	p += 2;

	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
	
	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV2_CANCQUEUE);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

/**
 * 功能:
 *		取消订阅
 * 参数:
 *		QUOTELV_OPER	*aOper			操作结构指针
 *		int				aSubscribeId	订阅Id
 * 返回值:
 *		-
 * 注释:
 *		
 */
void QuoteLvOper_CancelSubscribe(QUOTELV_OPER *aOper, int aSubscribeId)
{
	QuoteLvSubscribe_Lock(aOper->pSubscribe);
	QUOTELV_SUBSCRIBE_ITEM	*pItem = QuoteLvSubscribe_GetItem(aOper->pSubscribe,aSubscribeId);
	
	if(pItem)
	{
		char * p = QuoteLvOper_PackHead(aOper,RQS_LV_CANCSUBS,0,FALSE);
		aOper->nSendLen += 4;
		aOper->HeadAsk.subid = QUOTELV_SUBSCRIBE_ID_CANCEL;
		ShortToBytes(1,p);
		p += 2;
		ShortToBytes(aSubscribeId,p);
		p += 2;
		QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
		IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
    
    if(aOper->pSocketOper)
    {
      QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
    }
		pItem->bIsEffective = FALSE;
	}
	
	QuoteLvSubscribe_UnLock(aOper->pSubscribe);
	
	//printf("\n QuoteLvOper_CancelSubscribe nCount = %d",aOper->pSubscribe->nCount);
}

void QuoteLvOper_CancelAllSubscribe(QUOTELV_OPER *aOper)
{
	
	QuoteLvSubscribe_Lock(aOper->pSubscribe);
	
	if (aOper->pSubscribe->nCount > 0)
	{
		int i = 0;
		char * p = QuoteLvOper_PackHead(aOper,RQS_LV_CANCSUBS,0,FALSE);
		aOper->nSendLen = 2 + 2*aOper->pSubscribe->nCount;
		ShortToBytes(aOper->pSubscribe->nCount,p);
		p += 2;
		
		for(; i<aOper->pSubscribe->nCount; i++)
		{
			QUOTELV_SUBSCRIBE_ITEM	*pItem = QuoteLvSubscribe_GetIndexItem(aOper->pSubscribe,i);
			
			if (pItem) {
				ShortToBytes(pItem->Id,p);
				pItem->bIsEffective = FALSE;
				p += 2;
			}
			
		}
		
		aOper->HeadAsk.subid = QUOTELV_SUBSCRIBE_ID_ALLCANCEL;
		QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
		IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度
    
    if(aOper->pSocketOper)
    {
      QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
    }
	}
	
	QuoteLvSubscribe_UnLock(aOper->pSubscribe);
	
	//printf("\n QuoteLvOper_CancelAllSubscribe nCount = %d",aOper->pSubscribe->nCount);
	
}

void QuoteLvOper_ResetSubscribe(QUOTELV_OPER *aOper)
{
	QuoteLvSubscribe_Lock(aOper->pSubscribe);
	
	if (aOper->pSubscribe->nCount > 0)
	{
		int i = 0;
		memset(aOper->pSendData,0,OPER_SEND_LEN);
		aOper->nSendLen = 0;
		
		for(; i<aOper->pSubscribe->nCount; i++)
		{
			QUOTELV_SUBSCRIBE_ITEM	*pItem = QuoteLvSubscribe_GetIndexItem(aOper->pSubscribe,i);
			
			if (pItem) {
				memcpy(aOper->pSendData+aOper->nSendLen,pItem->pData,pItem->nLen);
				aOper->nSendLen += pItem->nLen;
			}
		}
		
		QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	}
	
	QuoteLvSubscribe_UnLock(aOper->pSubscribe);
}

void QuoteLvOper_CanceFundList(QUOTELV_OPER *aOper, int aId)
{
	QuoteLvSubscribe_Lock(aOper->pSubscribe);
	QUOTELV_SUBSCRIBE_ITEM	*pItem = QuoteLvSubscribe_GetItem(aOper->pSubscribe, aId);
	
	if(pItem)
	{
		pItem->bIsEffective = FALSE;
		HttpTools_Cancel(pItem->HttpId);
	}
	
	QuoteLvSubscribe_UnLock(aOper->pSubscribe);
	
}

int QuoteLvOper_SendData(QUOTELV_OPER *aOper, char* aData, int aLen)
{
  //Test
//  strcpy(aOper->pSocketAdd, "115.29.244.234");//沪港通
//  strcpy(aOper->pSocketAdd, "121.14.104.156");
  //
  
  if (aOper->HeadAsk.funcid == RQS_LV_RELINFO) {//判断是否是个股资讯或是信息地雷的请求，如是走以下请求
    //个股资讯改成走http。url暂写S
//      char *pUrl = "http://112.124.27.71:2011/";
    HttpTools_GetData(0, aOper->pHttpInfoUrl, aOper->pSendData, aOper->nSendLen, "application/x-www-form-urlencoded", QuoteLvOper_HttpNoRefResedData, aOper);
    return 0;
  }
  
	if (aOper->nConType == QUOTELV_CONNECTION_SOCKET)	//socket
	{
		//发送数据
    if (!SocketInterface_IsHaveConnect(aOper->pSocketOper)) {
      SocketInterface_ConnectToServer(aOper->pSocketOper);
    }
    SocketInterface_WriteBytes(aOper->pSocketOper, aData, aLen);
		return 0;
		
	}
	else
	{		//http
		QuoteLvOper_HttpRef(aOper);
		return 0;
	}
}


int QuoteLvOper_SendDictData(QUOTELV_OPER *aOper, char* aData, int aLen)
{
	if (aOper->nConType == QUOTELV_CONNECTION_SOCKET)	//socket
	{
		//发送数据
    if (!SocketInterface_IsHaveConnect(aOper->pSocketDictOper)) {
      SocketInterface_ConnectToServer(aOper->pSocketDictOper);
    }
    SocketInterface_WriteBytes(aOper->pSocketDictOper, aData, aLen);
	}
  return 0;
}


/**
 * 功能:
 *		Socket状态回调接受函数
 * 参数:
 *		void *pCBObj            socket状态回调方法对象，这里是QUOTELV_OPER
 *      int nStatus             socket状态码
 * 返回值:
 *		-
 * 注释:
 *		
 */
void QuoteLvOper_StockStatusNotice(void *pCBObj, int nStatus)
{
  QUOTELV_OPER *pOper = (QUOTELV_OPER*)pCBObj;
  switch(nStatus)
  {
    case SOCKET_STATUS_CONN:
    {
      //连接到行情服务器成功
      pOper->nSocketConnectErrorCount = 0;
    }
      break;
    case SOCKET_STATUS_NO_LOGIN:
    {
      if (pOper->pResErr)				//没登录
      {
        pOper->pResErr(pOper->pErrCBObj,NULL,QUOTE_STATUS_SERVER_NO_LOGIN);
      }
    }
      break;
    case SOCKET_STATUS_NO_LEVE2:
    {
      if (pOper->pResErr)				//leve2
      {
        pOper->pResErr(pOper->pErrCBObj,NULL,QUOTE_STATUS_SERVER_NO_LEVEL2);
      }
    }
      break;   
    case SOCKET_STATUS_SESSION_TIMEOUT:
    {
      if (pOper->pResErr)				//错误处理
      {
        pOper->pResErr(pOper->pErrCBObj,NULL,QUOTE_STATUS_SESSION_TIMEOUT);
      }
    }
      break;
      case SOCKET_STATUS_ERROR:
      {
          //socket error 重新自动连接,只自动连接3次
          pOper->nSocketConnectErrorCount++;
          if (pOper->nSocketConnectErrorCount<=3) {
              QuoteLvOper_ConnectQuoteServer(pOper);
              QuoteLvOper_ResetSubscribe(pOper);
          } else {
              if (pOper->pResErr)				//错误处理
              {
                  pOper->pResErr(pOper->pErrCBObj,NULL,QUOTE_STATUS_SERVER_ERROR);
              }
          }
      }
          break;
  }
}

void QuoteLvOper_ResedData(void *apObject, void *apData, int anSize)
{
	QUOTELV_OPER *pOper = (QUOTELV_OPER *)apObject;
	char *pData = apData;
  
//  //Test
//  printf("QuoteLvOper_ResedData \n %s",pData);
//  //
  
	int nPos = 0;
	int nPackLen = 0;
	
	//有可能是多个数据一起返回,所以要循环解包
	while (nPos<anSize)
	{
		nPackLen = BytesToInt(pData+nPos, 0);
		//跳过通信包头
		nPos+=5;	
		
		//更新数据
		QuoteLvOper_ParseData(pOper, pData+nPos, nPackLen);
		nPos += nPackLen;
	}
}

void QuoteLvOper_HttpResedData(HTTP_TOOLS *pHttp, int nType)
{
	QUOTELV_OPER *pOper = (QUOTELV_OPER *)pHttp->pCBObj;
	
	if (nType==HTTP_STATE_FINISH) {
		char *pData = pHttp->pRecvData;
    
		int nPos = 0;
		int nPackLen = 0;
		
		//有可能是多个数据一起返回,所以要循环解包
		while (nPos<pHttp->nRecvDataLen)
		{
			nPackLen = BytesToInt(pData+nPos, 0);
			//跳过通信包头
			nPos+=5;	
			
			//更新数据
			QuoteLvOper_ParseData(pOper, pData+nPos, nPackLen);
			nPos += nPackLen;
		}
	}
	else if(nType==HTTP_STATE_NET_ERROR)
	{
	}
	else if(nType==HTTP_STATE_TIME_OUT)
	{
		
	}
	
	TimeTools_Start(pOper->pQuoteTimer, QuoteLvOper_HttpRef, pOper, pOper->nRefTime, FALSE);
//	QuoteLvOper_HttpRef(pOper);
}


void QuoteLvOper_HttpNoRefResedData(HTTP_TOOLS *pHttp, int nType)
{
  QUOTELV_OPER *pOper = (QUOTELV_OPER *)pHttp->pCBObj;
  
  if (nType==HTTP_STATE_FINISH) {
    char *pData = pHttp->pRecvData;
    
//    //Test
//    printf("QuoteLvOper_HttpNoRefResedData\n %s",pHttp->pRecvData);
//    //
    
    int nPos = 0;
    int nPackLen = 0;
    
    //有可能是多个数据一起返回,所以要循环解包
    while (nPos<pHttp->nRecvDataLen)
    {
      nPackLen = BytesToInt(pData+nPos, 0);
      //跳过通信包头
      nPos+=5;
      
      //更新数据
      QuoteLvOper_ParseData(pOper, pData+nPos, nPackLen);
      nPos += nPackLen;
    }
  }
}

void QuoteLvOper_ResedFundData(HTTP_TOOLS *pHttp, int nType)
{
	if (nType==HTTP_STATE_FINISH) {
		QUOTELV_OPER *pOper = (QUOTELV_OPER *)pHttp->pCBObj;
		QuoteLvSubscribe_Lock(pOper->pSubscribe);
		QUOTELV_SUBSCRIBE_ITEM * item = QuoteLvSubscribe_GetHttpItem(pOper->pSubscribe,pHttp->nIndex);
		
		if (item == NULL)
		{
			return;
		}
		
		QuoteDataLV_ParseFundListData(pHttp->pRecvData,(QUOTELV_FUND_RES *)item->pRes);
		QUOTELV_FUND_RES *pFR = item->pRes;
		if (pFR) {
			Tools_Free(&pFR->Page.pCurPageUrl);
            pFR->Page.pCurPageUrl = (char*)Tools_Malloc(strlen(pHttp->pUrl)+1);
			strcpy(pFR->Page.pCurPageUrl, pHttp->pUrl);
		}
		QuoteLvSubscribe_UnLock(pOper->pSubscribe);
		
		item->pResedData(item->pCBObj,item);
	}
	else if(nType==HTTP_STATE_NET_ERROR)
	{
		printf("\n resed fund data net error");
	}
	else if(nType==HTTP_STATE_TIME_OUT)
	{
		printf("\n resed fund data time out");
	}
	
	
	
	//定时刷新
}


void QuoteLvOper_ResedFundVauleData(HTTP_TOOLS *pHttp, int nType)
{
	if (nType==HTTP_STATE_FINISH) {
		QUOTELV_OPER *pOper = (QUOTELV_OPER *)pHttp->pCBObj;
		QuoteLvSubscribe_Lock(pOper->pSubscribe);
		QUOTELV_SUBSCRIBE_ITEM * item = QuoteLvSubscribe_GetHttpItem(pOper->pSubscribe,pHttp->nIndex);
		
		if (item == NULL)
		{
			QuoteLvSubscribe_UnLock(pOper->pSubscribe);
			return;
		}
		
		int nPos = 0;
		int nPackLen = 0;
		nPackLen = BytesToInt(pHttp->pRecvData, 0);
		nPos += 5;	
		char *pData = pHttp->pRecvData+nPos;
		
		char *pPack = NULL;
		int nUnGZipLen = 0;
		
		//判断数据是否压缩
		nUnGZipLen = GZIP_Len((char*)pData, nPackLen);
		
		if (nUnGZipLen>0)//压缩
		{
			pPack = (char*)Tools_Malloc(nUnGZipLen);
			GZIP_inflate((char*)pData, nPackLen, pPack);
			nPackLen = nUnGZipLen;
		}
		else
		{
			pPack = (char*)pData;
		}
		
		if (pPack[0]!=0x01 || pPack[5] != 0x39)
		{
			//不是行情数据，直接返回
			if (nUnGZipLen>0)
			{
				Tools_Free((void**)&pPack);
			}
			
			QuoteLvSubscribe_UnLock(pOper->pSubscribe);
			return;
		}
		
		QuoteDataLV_ParseFundMinData(pPack+7,(QUOTELV_FUND_MIN_RES *)item->pRes);
		
		if (nUnGZipLen>0)
		{
			Tools_Free((void**)&pPack);
		}
		
		QuoteLvSubscribe_UnLock(pOper->pSubscribe);

		item->pResedData(item->pCBObj,item);
	}
	else if(nType==HTTP_STATE_NET_ERROR)
	{
	}
	else if(nType==HTTP_STATE_TIME_OUT)
	{
	}
}

void QuoteLvOper_ResedFundInfoData(HTTP_TOOLS *pHttp, int nType)
{
	
	if (nType==HTTP_STATE_FINISH) {
		
		QUOTELV_OPER *pOper = (QUOTELV_OPER *)pHttp->pCBObj;
		QuoteLvSubscribe_Lock(pOper->pSubscribe);
		QUOTELV_SUBSCRIBE_ITEM * item = QuoteLvSubscribe_GetHttpItem(pOper->pSubscribe,pHttp->nIndex);
		
		char *aData = pHttp->pRecvData;
		int aLen = pHttp->nRecvDataLen;
		
		if (item == NULL)
		{
			QuoteLvSubscribe_UnLock(pOper->pSubscribe);
			return;
		}
		
		int nPackLen = 0;
		nPackLen = BytesToInt(aData, 0);
		aLen = nPackLen;
		aData = aData + 5;//跳过通信包头
		
		
		char *pPack = NULL;
		char *pUnGzp = NULL;
		nPackLen = 0;
		
		if (aData[0]!=0x02)		//不是行情数据，直接返回
		{
			//add by jason 解锁
			QuoteLvSubscribe_UnLock(pOper->pSubscribe);
			//end
			return;
		}
		
		int nUnGZipLen = GZIP_Len((char*)aData+1, aLen-1);		//业务标识不压缩了
		
		if (nUnGZipLen>0)			//判断数据是否压缩
		{
			pUnGzp = pPack = (char*)Tools_Malloc(nUnGZipLen+8);
			GZIP_inflate((char*)aData+1, aLen-1, pPack);
			nPackLen = nUnGZipLen;
		}
		else
		{
			pPack = (char*)aData+1;
			nPackLen = aLen-1;
		}
		
		
		
		//跳过业务标识
		//memcpy(&qResedHead, pPack+1, sizeof(QUOTE_RESED_HEAD));
		//包类型
		pOper->HeadRes.type = pPack[0];
		//顺序号
		pOper->HeadRes.seq = BytesToShort(pPack, 1);
		//协议版本号
		pOper->HeadRes.ver = pPack[3];
		//请求功能类型
		pOper->HeadRes.funcid = pPack[4];
		//终端语言
		pOper->HeadRes.language = pPack[5];
		//订阅id
		pOper->HeadRes.subid = BytesToShort(pPack,6);
		pPack += 8;
		nPackLen -= 8;
		
		QuoteDataLV_ParseStockInfoData(pPack,(QUOTELV_STOCKINFO_RES*)item->pRes,pOper->HeadRes.type);
		
		if (nUnGZipLen>0)
		{
			Tools_Free((void**)&pUnGzp);
		}
		
		QuoteLvSubscribe_UnLock(pOper->pSubscribe);
		
		item->pResedData(item->pCBObj,item);
	}
	else if(nType==HTTP_STATE_NET_ERROR)
	{
	}
	else if(nType==HTTP_STATE_TIME_OUT)
	{
	}
}
	

void QuoteLvOper_ParseData(QUOTELV_OPER *aOper, char* aData, int aLen)
{
//  //Test
//  printf("QuoteLvOper_ParseData \n %s",aData);
//  //
  
	char *pPack = NULL;
	char *pUnGzp = NULL;
	int nPackLen = 0;
	
	if (aData[0]!=0x02)		//不是行情数据，直接返回
	{
		return;
	}
	
	int nUnGZipLen = GZIP_Len((char*)aData+1, aLen-1);		//业务标识不压缩了
	
	if (nUnGZipLen>0)			//判断数据是否压缩
	{
		pUnGzp = pPack = (char*)Tools_Malloc(nUnGZipLen+8);
		GZIP_inflate((char*)aData+1, aLen-1, pPack);
		nPackLen = nUnGZipLen;
	}
	else
	{
		pPack = (char*)aData+1;
		nPackLen = aLen-1;
	}
	
	
	
	//跳过业务标识
	//memcpy(&qResedHead, pPack+1, sizeof(QUOTE_RESED_HEAD));
	//包类型
	aOper->HeadRes.type = pPack[0];
	//顺序号
	aOper->HeadRes.seq = BytesToShort(pPack, 1);
	//协议版本号
	aOper->HeadRes.ver = pPack[3];
	//请求功能类型
	aOper->HeadRes.funcid = pPack[4];
	//终端语言
	aOper->HeadRes.language = pPack[5];
	//订阅id
	aOper->HeadRes.subid = BytesToShort(pPack,6);
	pPack += 8;
	nPackLen -= 8;
	
	
	QuoteLvSubscribe_ClearInvalidItem(aOper->pSubscribe);		
  
	QUOTELV_SUBSCRIBE_ITEM * item = QuoteLvSubscribe_GetItem(aOper->pSubscribe,aOper->HeadRes.subid);
	
	if (item == NULL)
	{
		if (nUnGZipLen>0)
		{
			Tools_Free((void**)&pUnGzp);
		}
		
		return;
	}
	
	switch(aOper->HeadRes.type)
	{
		case QUOTE_LV_TYPE_ALL:
		case QUOTE_LV_TYPE_POINT:
		{
			//全数据包
			switch (aOper->HeadRes.funcid)
			{
				case RQS_LV_CODELIST:
				{
					QUOTELV_DICT_RES * res = (QUOTELV_DICT_RES *)item->pRes;
					QuoteDataLV_ParseDictData(pPack,res);
					//imuse 修正,先更新数据，然后再存版本号。
					//DictionaryTools_WriteVerData(res->pVerData, res->sVerLen);
					if (res->nDictLen > 0) {
						DictionaryTools_UpData(res->pDictdata, res->nDictLen);
					}
					DictionaryTools_WriteVerData(res->pVerData, res->sVerLen);
          
          if (aOper->pDicUpdateTime[0] != '\0') {
             FileTools_WriteDataEx("updatetime.data", aOper->pDicUpdateTime, strlen(aOper->pDicUpdateTime));
          }
				}
					break;
				case RQS_LV_MIN:			//分时数据		
				{
					//add by jason 验证订阅id
					QUOTELV_MIN_RES *aMinRes = (QUOTELV_MIN_RES*)item->pRes;
					if (aMinRes->nSubID == aOper->HeadRes.subid) {
						QuoteDataLV_ParseMinData(pPack,(QUOTELV_MIN_RES*)item->pRes,aOper->HeadRes.funcid,aOper->HeadRes.type);
					}
				}
					break;
				case RQS_LV_DFTMIN:			//默认分时数据
				{
					//add by jason 验证订阅id
					QUOTELV_MIN_RES *aMinRes = (QUOTELV_MIN_RES*)item->pRes;
					if (aMinRes->nSubID == aOper->HeadRes.subid) {
						QuoteDataLV_ParseDFTMinData(pPack,(QUOTELV_MIN_RES*)item->pRes,aOper->HeadRes.type);
					}
					//end
				}
					break;
				case RQS_LV_HISMIN:			//历史分时
				{
					QuoteDataLV_ParseMinData( pPack,(QUOTELV_MIN_RES*)item->pRes,aOper->HeadRes.funcid,aOper->HeadRes.type);
				}	
					break;
        //lisz add 20110916 start
        case RQS_LEVEL2_MIN_TRANC:			//分时数据		
				{
					//add by jason 验证订阅id
					QUOTELV_MIN_RES *aMinRes = (QUOTELV_MIN_RES*)item->pRes;
					if (aMinRes->nSubID == aOper->HeadRes.subid) {
						QuoteDataLV_ParseLeve2MinData(pPack,(QUOTELV_MIN_RES*)item->pRes,aOper->HeadRes.funcid,aOper->HeadRes.type);
					}
				}
					break;
        //lisz add 20110916 end
				case RQS_LV_DETAIL:	//明细数据
				{
					//add by jason 验证订阅id
					QUOTELV_DETAIL_RES *aDetailRes = (QUOTELV_DETAIL_RES*)item->pRes;
					if (aDetailRes->nSubID == aOper->HeadRes.subid) {//订阅id相同,解析数据
						QuoteDataLV_ParseDetailData(pPack,(QUOTELV_DETAIL_RES*)item->pRes,aOper->HeadRes.type,((QUOTELV_DETAIL_ASK*)item->pAsk)->count);
					}
					//end
					
				}
					break;
				case RQS_LV2_DETAIL:  //Level-2 明细数据
				{
					//add by jason 订阅id判断
					QUOTELV_DETAIL_RES *aDetailRes = (QUOTELV_DETAIL_RES*)item->pRes;
					if (aDetailRes->nSubID == aOper->HeadRes.subid) {//订阅id相同,解析数据
						QuoteDataLV_ParseDetailLvData(pPack,(QUOTELV_DETAIL_RES*)item->pRes,aOper->HeadRes.type,((QUOTELV_DETAIL_ASK*)item->pAsk)->count);
					}
					
				}
					break;
				case RQS_LV_GGRT:	//报价数据
				{
					QuoteDataLV_ParsePriceData(pPack,aOper->HeadRes.type,(QUOTELV_PRICE_RES*)item->pRes);
				}
					break;
				case RQS_LV_ZXGRT:	//自选股数据
				{
          if(item->pRes == &aOper->OwnAllRes){
              QuoteDataLV_ParseOwnAllData(pPack,(QUOTELV_OWNALL_RES *)item->pRes,aOper->HeadRes.type);
          }else{
             QuoteDataLV_ParseOwnData(pPack,(QUOTELV_OWN_RES *)item->pRes,aOper->HeadRes.type); 
          }
				}
					break;
				case RQS_LV_HSINDEXLIST:	//BTexokex
				case RQS_LV_HKINDEXLIST:	//港股okex
				case RQS_LV_SIFLIST:		//股指期货
				{
					QuoteDataLV_ParseIndexData(pPack,(QUOTELV_INDEX_RES*)item->pRes,aOper->HeadRes.type);
				}	
					break;
				case RQS_LV_BOARDRANK:		//板块排行数据
				{
					QuoteDataLV_ParseBlockData(pPack,(QUOTELV_BLOCK_RES*)item->pRes);
				}
					break;
				case RQS_LV_BORADINDEX:		//板块okex排行数据
				{
					QuoteDataLV_ParseBlockIndexData(pPack,(QUOTELV_BLOCK_RES*)item->pRes);
				}
					break;
				case RQS_LV2_LSTNTICK:	//Level2最新N条逐笔
				{
					QuoteDataLV_ParseIndividData(pPack,(QUOTELV_INDIVID_RES*)item->pRes,aOper->HeadRes.type,((QUOTELV_INDIVID_ASK*)item->pAsk)->count);
				}
					break;
				case RQS_LV2_BSQUEUE:			//Level-2最新委托队列
				{
					QuoteDataLV_ParseTrustData(pPack,(QUOTELV_TRUST_RES*)item->pRes,aOper->HeadRes.type);
				}
					break;
				case RQS_LV_RELINFO:				//个股相关的资讯订阅
				{
					QuoteDataLV_ParseStockInfoData(pPack,(QUOTELV_STOCKINFO_RES*)item->pRes,aOper->HeadRes.type);
				}
					break;
				case RQS_LV_KLINE:				//K线数据
        {
          QuoteDataLV_ParseKData(pPack,(QUOTELV_K_RES *)item->pRes,aOper->HeadRes.type,((QUOTELV_K_ASK*)item->pAsk)->count,aOper->nAddedOffset,FALSE);//不带除复权非压缩解析
        }
          break;
        case RSQ_LV_RQS_EXDIVIKLINE:
				{

          QuoteDataLV_ParseKData2(pPack,(QUOTELV_K_RES *)item->pRes,aOper->HeadRes.type,((QUOTELV_K_ASK*)item->pAsk)->count,aOper->nAddedOffset,TRUE);//带除复权压缩解析
          
					//	QuoteLvKIndex_calcDMA(aOper->KIndex,(QUOTELV_K_RES *)item->pRes);
					//	QuoteLvKIndex_calcBOLL(aOper->KIndex,(QUOTELV_K_RES *)item->pRes);
					//	QuoteLvKIndex_calcMACD(aOper->KIndex,k->kData,k->nMaxCount,aOper->nAddedOffset,k->nTotalCount);
					//	QuoteLvKIndex_calcKDJ(aOper->KIndex,(QUOTELV_K_RES *)item->pRes);
					//	QuoteLvKIndex_calcPriceAVG(aOper->KIndex,(QUOTELV_K_RES *)item->pRes);
					//	QuoteLvKIndex_calcRSI(aOper->KIndex,(QUOTELV_K_RES *)item->pRes);
					//	QuoteLvKIndex_calcVolAVG(aOper->KIndex,(QUOTELV_K_RES *)item->pRes);
					//	QuoteLvKIndex_calcDMI(aOper->KIndex,(QUOTELV_K_RES *)item->pRes);
				}
					break;
        case RQS_LEVEL2_TRANS_ORDER:
        {
          QuoteDataLV_ParseLeve2KData(pPack,
                                      (QUOTELV_K_RES *)item->pRes,
                                      aOper->HeadRes.type,
                                      ((QUOTELV_LEVE2_K_ASK*)item->pAsk)->count,
                                      aOper->nAddedOffset);
        }
          break;
        case RQS_LEVEL2_TRANS_TRANC:
        {
          QuoteDataLV_ParseLeve2TrancKData(pPack,
                                           (QUOTELV_K_RES*)item->pRes,
                                           aOper->HeadRes.type,
                                           ((QUOTELV_LEVE2_TRANC_K_ASK*)item->pAsk)->count,
                                           aOper->nAddedOffset);
        }
          break;
				case  RQS_LV2_INDVOL:				//逐笔成交量统计
				{
					QuoteDataLV_ParseIndividVolData(pPack,(QUOTELV_INDIVID_VOL_RES*)item->pRes,aOper->HeadRes.type);
				}
					break;
        case  RQS_LV_HOTCONCEPT:
        {
          QuoteDataLV_ParseHotData(pPack,(QUOTELV_HOT_DIR_RES*)item->pRes);
        }
          break;
				case  RQS_LV2_DATASELSTOCK:			//最优选股
				{
					QuoteDataLV_ParseSelStockData(pPack,(QUOTELV_SEL_STOCK_RES*)item->pRes);
				}
				break;
			case  RQS_LV2_DATASELDIRLIST:		//数据选股目录列表
				{
					QuoteDataLV_ParseSelDirListData(pPack,(QUOTELV_SEL_DIRLIST_RES*)item->pRes);
				}
				break;
			case RQS_LV2_CANCQUEUE:			
					//个股撤单队列
				{
					QuoteDataLV_ParseCancelTrustData(pPack,(QUOTELV_CANCELTRUST_RES*)item->pRes,aOper->HeadRes.type,((QUOTELV_CANCELTRUST_ASK*)item->pAsk)->count);
				}
          break;
        default :
          
          QuoteLvOper_CancelSubscribe(aOper, item->Id);
          if (aOper->pResErr)				//错误处理
          {
            aOper->pResErr(aOper->pErrCBObj,pPack,QUOTE_STATUS_SERVER_ERROR);
          }
					
          if (nUnGZipLen>0)
          {
            Tools_Free((void**)&pUnGzp);
          }
          
          return;
					
          break;
			}
		}
			break;
		case QUOTE_LV_TYPE_NO:
		default:
			break;
	}
	

	
	if (nUnGZipLen>0)
	{
		Tools_Free((void**)&pUnGzp);
	}
	
	if (item->pResedData && item->pCBObj) {
		//item->pResedData(item->pCBObj,item);
		STInterface_resedData(item);
	}
	
	item->HeadType = QUOTE_LV_TYPE_POINT;
	
}

char* QuoteLvOper_PackHead(QUOTELV_OPER *aOper, int aType, int aSubscribeId, TBOOL aIsSubscribe)
{
	aOper->nSendLen = 0;
	memset(aOper->pSendData,0,OPER_SEND_LEN);
	char *p = aOper->pSendData;
	
	//打包传输数据包
	p[4] = 0x01;		//
	p[5] = 0x02;		//新行情
	p += QUOTELV_PASS_LEN;
	aOper->nSendLen += QUOTELV_PASS_LEN;
	
	//打包行情包头
	if (aSubscribeId == 0)
	{
		aOper->HeadAsk.type = 1;
	}
	else
	{
		aOper->HeadAsk.type = 2;
	}
	aOper->HeadAsk.funcid = aType;
	aOper->HeadAsk.seq = aIsSubscribe;
	p += QUOTELV_HEAD_LEN;
	aOper->nSendLen += QUOTELV_HEAD_LEN;
	
	aOper->HeadAsk.subid = aOper->nSubscribeId++; 
	return p;
}

TBOOL QuoteLvOper_IsOwnCode(QUOTELV_OPER *aOper, char* aCode, char aMacketId)
{
	TBOOL bRet;
	int nPos =0;
	bRet = FALSE;
	
	char pContent[8];
	memset(pContent,0,8);
	memcpy(pContent,aCode,6);
	pContent[6] = aMacketId;
	
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnPath);
	if (f_data && f_data->nSize > 6)
	{
		while (nPos < f_data->nSize)
		{
			if ( memcmp(f_data->pData + nPos, pContent,7)==0)
			{
				bRet = TRUE;
				break;
			}
			nPos += 7;
		}
	}
	FileTools_FreeData(f_data);
	return bRet;
}

int  QuoteLvOper_AddOwnCode(QUOTELV_OPER *aOper, char* aCode, char aMacketId)
{
	if (aCode == NULL || strlen(aCode) == 0)
	{
		return -1;
	}
	
	int rest = -1;
	int nPos =0;
	char *tempData = NULL;
	char pContent[8];
	memset(pContent,0,8);
  
//  if (strlen(aCode) == 5) {
//    memcpy(pContent,aCode,5);
//    pContent[5] = aMacketId;
//  }else{
    memcpy(pContent,aCode,6);
    pContent[6] = aMacketId;
  //}

	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnPath);
	
	if (f_data && f_data->nSize > 6)
	{
		while (nPos < f_data->nSize)
		{
			if ( memcmp(f_data->pData + nPos, pContent,7)==0)
			{
				rest = 1;
				break;
			}
			nPos += 7;
		}
		
		if (rest != 1)
		{
			tempData = (char *)Tools_Malloc(f_data->nSize + 8);
            memcpy(tempData,pContent,7);
			memcpy(tempData+7,f_data->pData,f_data->nSize);
			
			FileTools_WriteDataEx(aOper->pOwnPath,tempData,f_data->nSize + 7);
			Tools_Free((void **)&tempData);
			rest = 0;
			aOper->nOwnMaxCount++;
		}
	}
	else
	{
		FileTools_WriteDataEx(aOper->pOwnPath,pContent,7);
		rest = 0;
		aOper->nOwnMaxCount++;
	}
	
	Tools_Free((void **)&tempData);
	FileTools_FreeData(f_data);
	return rest;
	
}

int QuoteLvOper_DelOwnCode(QUOTELV_OPER *aOper, char* aCode, char aMacketId)
{
	if (aCode == NULL)
	{
		return -1;
	}
	
	int rest = -1;
	int nPos =0;
	char *tempData = NULL;
	char pContent[8];
	memset(pContent,0,8);
	memcpy(pContent,aCode,6);
	pContent[6] = aMacketId;
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnPath);
	
	if (f_data && f_data->nSize > 6)
	{
		while (nPos < f_data->nSize)
		{
			if ( memcmp(f_data->pData + nPos, pContent,7)==0)
			{
				rest = 1;
				break;
			}
			nPos += 7;
		}
		
		if (rest == 1)
		{
			tempData = (char *)Tools_Malloc(f_data->nSize - 6);
			
			if (nPos >= 7)
			{
				memcpy(tempData,f_data->pData,nPos);
			}
			
			memcpy(tempData + nPos,f_data->pData + nPos + 7,f_data->nSize - nPos - 7);
			FileTools_WriteDataEx(aOper->pOwnPath,tempData,f_data->nSize - 7);
			Tools_Free((void **)&tempData);
			rest = 0;
			aOper->nOwnMaxCount--;
		}
	}
	else
	{
		rest = -1;
	}
	
	Tools_Free((void **)&tempData);
	FileTools_FreeData(f_data);
	return rest;
	
}

void QuoteLvOper_ChangeOwnPos(QUOTELV_OPER *aOper, int aScrPos, int aDesPos)
{
	int count = QuoteLvOper_GetOwnCount(aOper);
	
	if ( aScrPos == aDesPos || aScrPos < 0 || aDesPos < 0 || aScrPos >= count || aDesPos >= count)
	{
		return;
	}
	
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnPath);
	
	if (f_data && f_data->nSize > 6)
	{
		int pos = aScrPos * 7;
		int pos1 = aDesPos * 7;
		char temp[7];
		memset(temp,0,7);
		
		
		if (aScrPos>aDesPos) {
			//
			memcpy(temp,f_data->pData+pos,7);
			MOVEMEM(f_data->pData+pos1, f_data->pData+pos1+7, pos-pos1);
			memcpy(f_data->pData+pos1, temp, 7);
		}
		else
		{
			memcpy(temp,f_data->pData+pos,7);
			memcpy(f_data->pData+pos, f_data->pData+pos+7, pos1-pos);
			memcpy(f_data->pData+pos1, temp, 7);
		}
		
		//memcpy(f_data->pData+pos,f_data->pData+pos1,7);
		//memcpy(f_data->pData+pos1,temp,7);
		FileTools_WriteDataEx(aOper->pOwnPath,f_data->pData,f_data->nSize);
		FileTools_FreeData(f_data);
	}
	
}

int QuoteLvOper_getOwnCodePos(QUOTELV_OPER *aOper, char* aCode, char aMacketId)
{
    if (aCode == NULL)
	{
		return -1;
	}
	
	int codePos = -1;
	int nPos =0;
    int i = 0;
	char *tempData = NULL;
	char pContent[8];
	memset(pContent,0,8);
	memcpy(pContent,aCode,6);
	pContent[6] = aMacketId;
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnPath);
	
	if (f_data && f_data->nSize > 6)
	{
		while (nPos < f_data->nSize)
		{
			if ( memcmp(f_data->pData + nPos, pContent,7)==0)
			{
                codePos = i;
				break;
			}
			nPos += 7;
            i++;
		}
	}
	else
	{
		codePos = -1;
	}
	
	Tools_Free((void **)&tempData);
	FileTools_FreeData(f_data);
	return codePos;
}

int QuoteLvOper_GetOwnCount(QUOTELV_OPER *aOper)
{
	int nCount = 0;
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnPath);
	
	if (f_data && f_data->nSize > 6)
	{
		nCount = f_data->nSize / 7;
		FileTools_FreeData(f_data);
	}
	
	return nCount;
}

void QuoteLvOper_DelAllOwnCode(QUOTELV_OPER *aOper)
{
	FileTools_WriteDataEx(aOper->pOwnPath,"",0);
	aOper->nOwnMaxCount = 0;
}

void QuoteLvOper_UpdateOwnAllCode(QUOTELV_OPER *aOper, char *pBuf, int nSize)
{
	if (nSize>=7 && nSize%7==0) {
		FileTools_WriteDataEx(aOper->pOwnPath,pBuf,nSize);
		aOper->nOwnMaxCount = nSize/7;
	}
}

char* QuoteLvOper_GetAllOwnCode(QUOTELV_OPER *aOper)
{
	char *str = NULL;
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnPath);
	
	if (f_data && f_data->nSize > 6)
	{
		str = (char *) Tools_Malloc(f_data->nSize+8);
		_i2b(f_data->nSize, str);
		memcpy(str+4,f_data->pData,f_data->nSize);
		FileTools_FreeData(f_data);
	}
	
	return str;
}

int QuoteLvOper_GetByte(QUOTELV_OPER *aOper, char* aData, int aIndex, short aPageCount)
{
	int nPageCount = 0;
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnPath);
	int nPageLen = 7;
	
	if (f_data && f_data->nSize > 6)
	{
		
		if (f_data->nSize >= aIndex*nPageLen)				//能取到符合要求的数据
		{
			int Len = f_data->nSize - aIndex * nPageLen;
			Len = Len > 7*aPageCount ?  7*aPageCount : Len;
			
			if(aData)
			{
				memcpy(aData,f_data->pData+aIndex*nPageLen,Len);
			}
			
			nPageCount = Len/7;
			
		}
	}
	
	FileTools_FreeData(f_data);
	return nPageCount;
}


int  QuoteLvOper_IsOwnFundCode(QUOTELV_OPER *aOper, char* aCode, char aMacketId)
{
	TBOOL bRet;
	int nPos =0;
	bRet = FALSE;
	
	char pContent[8];
	memset(pContent,0,8);
	memcpy(pContent,aCode,6);
	pContent[6] = aMacketId;
	
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnFundPath);
	
	if (f_data && f_data->nSize > 6)
	{
		while (nPos < f_data->nSize)
		{
			int nLen = f_data->pData[nPos];
			
			if ( memcmp(f_data->pData + nPos + 1, pContent,7)==0)
			{
				bRet = TRUE;
				break;
			}
			
			nPos = nPos + nLen;
		}
		
		FileTools_FreeData(f_data);
	}
	
	
	
	if (bRet) {
		return nPos;
	}
	else {
		return -1;
	}

}


int  QuoteLvOper_AddOwnFundCode(QUOTELV_OPER *aOper, char* aCode, char aMacketId, char* pName)
{
	if (aCode == NULL || strlen(aCode) == 0)
	{
		return -1;
	}
	
	if (QuoteLvOper_IsOwnFundCode(aOper,aCode,aMacketId) >= 0) {
		return 1;
	}
	int rest = -1;
	int nLen = strlen(pName) + 8;
	char *tempData = NULL;
	char *pContent = (char*)Tools_Malloc(nLen);
	memset(pContent,0,nLen);
	pContent[0] = nLen;
	memcpy(pContent+1,aCode,6);
	pContent[7] = aMacketId;
	memcpy(pContent+8, pName, strlen(pName));
	
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnFundPath);
	
	if (f_data && f_data->nSize > 6)
	{
		tempData = (char *)Tools_Malloc(f_data->nSize + nLen);
		memcpy(tempData,pContent,nLen);
		memcpy(tempData+nLen,f_data->pData,f_data->nSize);
		FileTools_WriteDataEx(aOper->pOwnFundPath,tempData,f_data->nSize + nLen);
		Tools_Free((void **)&tempData);
		rest = 0;
	}
	else
	{
		FileTools_WriteDataEx(aOper->pOwnFundPath,pContent,nLen);
		rest = 0;
	}
	
	Tools_Free((void **)&tempData);
	Tools_Free((void**)&pContent);
	FileTools_FreeData(f_data);
	return rest;
}


int QuoteLvOper_DelOwnFundCode(QUOTELV_OPER *aOper, char* aCode, char aMacketId)
{
	int nPos =0; 
	if (aCode == NULL || (nPos = QuoteLvOper_IsOwnFundCode(aOper,aCode,aMacketId)) < 0)
	{
		return -1;
	}
	
	int rest = -1;
	char *tempData = NULL;
	char pContent[8];
	memset(pContent,0,8);
	memcpy(pContent,aCode,6);
	pContent[6] = aMacketId;
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnFundPath);
	
	if (f_data && f_data->nSize > 6)
	{
		char *p = f_data->pData + nPos;
		int nLen = p[0];
		tempData = (char *)Tools_Malloc(f_data->nSize - nLen);
		
		if (nPos >= 7)
		{
			memcpy(tempData,f_data->pData,nPos);
		}
		
		memcpy(tempData + nPos,f_data->pData + nPos + nLen,f_data->nSize - nPos - nLen);
		FileTools_WriteDataEx(aOper->pOwnFundPath,tempData,f_data->nSize - nLen);
		Tools_Free((void **)&tempData);
		rest = 0;
	}
	else
	{
		rest = -1;
	}
	
	Tools_Free((void **)&tempData);
	FileTools_FreeData(f_data);
	return rest;
	
}


void QuoteLvOper_ChangeOwnFundPos(QUOTELV_OPER *aOper, int aScrPos, int aDesPos)
{
	int count = QuoteLvOper_GetOwnFundCount(aOper);
	
	if ( aScrPos == aDesPos || aScrPos < 0 || aDesPos < 0 || aScrPos >= count || aDesPos >= count)
	{
		return;
	}
	
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnFundPath);
	
	if (f_data && f_data->nSize > 6)
	{
		int pos = 0;
		int pos1 = 0;
		int nScrLen = 0;
		int nDesLen = 0;
		int i = 0;
		char *p = f_data->pData;
		
		for (; i<aScrPos; i++) {
			int nLen = p[0];
			pos += nLen;
			p = p + nLen;
		}
		
		nScrLen = p[0];
		
		p = f_data->pData;
		
		for (i=0; i<aDesPos; i++) {
			int nLen = p[0];
			pos1 += nLen;
			p = p + nLen;
		}
		
		nDesLen = p[0];
		
		char temp[MAX_PATH];
		memset(temp,0,MAX_PATH);
		
		
		if (aScrPos>aDesPos) {
			memcpy(temp,f_data->pData+pos,nScrLen);
			MOVEMEM(f_data->pData+pos1, f_data->pData+pos1+nScrLen, pos-pos1);
			memcpy(f_data->pData+pos1, temp, nScrLen);
		}
		else
		{
			memcpy(temp,f_data->pData+pos,nScrLen);
			memcpy(f_data->pData+pos, f_data->pData+pos+nScrLen, pos1+nDesLen-(pos + nScrLen));
			memcpy(f_data->pData+pos1+nDesLen - nScrLen, temp, nScrLen);
		}
		

		FileTools_WriteDataEx(aOper->pOwnFundPath,f_data->pData,f_data->nSize);
		FileTools_FreeData(f_data);
	}
	
}

int QuoteLvOper_GetOwnFundCount(QUOTELV_OPER *aOper)
{
	int nCount = 0;
	int nPos = 0;
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnFundPath);
	
	if (f_data && f_data->nSize > 6)
	{
		char *p = f_data->pData;
		
		while (nPos < f_data->nSize) {
			int nLen = p[nPos];
			nCount++;
			nPos += nLen;
			
		}
		FileTools_FreeData(f_data);
	}
	
	return nCount;
}

char* QuoteLvOper_GetAllOwnFundCode(QUOTELV_OPER *aOper)
{
	char *str = NULL;
	FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pOwnFundPath);
	
	if (f_data && f_data->nSize > 6)
	{
		str = (char *) Tools_Malloc(f_data->nSize+8);
		_i2b(f_data->nSize, str);
		memcpy(str+4,f_data->pData,f_data->nSize);
		FileTools_FreeData(f_data);
	}
	
	return str;
}

void QuoteLvOper_DelAllOwnFundCode(QUOTELV_OPER *aOper)
{
	FileTools_WriteDataEx(aOper->pOwnFundPath,"",0);
}

char* QuoteLvOper_GetFundListUrl(QUOTELV_OPER *aOper, char *aUrl, int aFundType, int aPageCount)
{
	if (aUrl == NULL || aPageCount < 0)
	{
		return NULL;
	}
	
	strcpy(aOper->pSendData,aUrl);
	int Len = strlen(aOper->pSendData);
	
	char sUrl[MAX_PATH];
	memset(sUrl,0,sizeof(sUrl));
	strcpy(sUrl, aOper->pSendData);
	
	if (aOper->pSendData[Len-1] != '?')
	{
		strcat(sUrl,"&");
	}
	
	switch(aFundType)
	{
		case QUOTELV_FUND_COMPANY:		//	基金公司
		{
			sprintf(aOper->pSendData,"%sctype=fundcompany&pagesize=%d",sUrl, aPageCount);
		}
			break;
		case QUOTELV_FUND_SH:			//上证基金
		{
			sprintf(aOper->pSendData,"%sctype=navlist&pagesize=%d&fundtype=shangzheng",sUrl, aPageCount);
		}
			break;
		case QUOTELV_FUND_SZ:			//深证基金
		{
			sprintf(aOper->pSendData,"%sctype=navlist&pagesize=%d&fundtype=shenzheng",sUrl, aPageCount);
		}
			break;
		case QUOTELV_FUND_OPEN:			//开发式基金
		{
			sprintf(aOper->pSendData,"%sctype=navlist&pagesize=%d&fundtype=open",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_CLOSE:		//封闭式基金
		{
      //add by jason 取静态页面
			//sprintf(aOper->pSendData,"%sctype=quote&pagesize=%d&fundtype=close",sUrl,aPageCount);
      sprintf(aOper->pSendData,"%sctype=navlist&pagesize=%d&fundtype=close",sUrl,aPageCount);
      //end
		}
			break;
		case QUOTELV_FUND_LOF:			//LOF基金
		{
      //add by jason 取静态页面
			//sprintf(aOper->pSendData,"%sctype=quote&pagesize=%d&fundtype=lof",sUrl,aPageCount);
      sprintf(aOper->pSendData,"%sctype=navlist&pagesize=%d&fundtype=lof",sUrl,aPageCount);
      //end
		}
			break;
		case QUOTELV_FUND_ETF:			//ETF基金
		{
      //add by jason 取静态页面
			//sprintf(aOper->pSendData,"%sctype=quote&pagesize=%d&fundtype=etf",sUrl,aPageCount);
      sprintf(aOper->pSendData,"%sctype=navlist&pagesize=%d&fundtype=etf",sUrl,aPageCount);
		  //end
    }
			break;
		case QUOTELV_FUND_QUOTE_SH:			//上证基金行情
		{
			sprintf(aOper->pSendData,"%sctype=quote&pagesize=%d&fundtype=shangzheng",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_QUOTE_SZ:			//深证基金行情
		{
			sprintf(aOper->pSendData,"%sctype=quote&pagesize=%d&fundtype=shenzheng",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_QUOTE_CLOSE:		//封闭式基金行情
		{
			sprintf(aOper->pSendData,"%sctype=quote&pagesize=%d&board=38",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_QUOTE_LOF:			//LOF基金行情
		{
			sprintf(aOper->pSendData,"%sctype=quote&pagesize=%d&board=34",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_QUOTE_ETF:			//ETF基金行情
		{
			sprintf(aOper->pSendData,"%sctype=quote&pagesize=%d&board=33",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_RATING_OPEN:			//开发式基金评级
		{
			sprintf(aOper->pSendData,"%sctype=fundgrade&pagesize=%d&fundtype=open",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_RATING_CLOSE:		//封闭式基金评级
		{
			sprintf(aOper->pSendData,"%sctype=fundgrade&pagesize=%d&fundtype=close",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_RATING_LOF:			//LOF基金评级
		{
			sprintf(aOper->pSendData,"%sctype=fundgrade&pagesize=%d&fundtype=lof",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_RATING_ETF:			//ETF基金评级
		{
			sprintf(aOper->pSendData,"%sctype=fundgrade&pagesize=%d&fundtype=etf",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_RATING_ACTIVE:		//积极型组合
		{
			sprintf(aOper->pSendData,"%sctype=fundcommend&pagesize=%d&commendtype=1",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_RATING_STEADY:	//稳健型组合
		{
			sprintf(aOper->pSendData,"%sctype=fundcommend&pagesize=%d&commendtype=2",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_RATING_CARE:	//保守型组合
		{
			sprintf(aOper->pSendData,"%sctype=fundcommend&pagesize=%d&commendtype=3",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_RATING:	//基金评级（安信特殊的）
		{
			sprintf(aOper->pSendData,"%sctype=fundrating&pagesize=%d",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_VALUECLOSE:		//基金净值封闭式
		{
			sprintf(aOper->pSendData,"%sctype=navlist&pagesize=%d&fundtype=close",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_VALUELOF:			//基金净值LOF
		{
			sprintf(aOper->pSendData,"%sctype=navlist&pagesize=%d&fundtype=lof",sUrl,aPageCount);
		}
			break;
		case QUOTELV_FUND_VALUEETF:			//基金净值ETF
		{
			sprintf(aOper->pSendData,"%sctype=navlist&pagesize=%d&fundtype=etf",sUrl,aPageCount);
		}
			break;
		default:
			return NULL;
	}
	//add by jason 增加useid及手机号，用户行为
  /*char *pUser;
  char *pSession;
  char *pMobile;
  char temp[128];
  memset(temp, 0, sizeof(temp));
  
  pUser = GetConfig(CONFIG_USER_ID);
  pSession = GetConfig(CONFIG_SESSION_ID);
  pMobile = GetConfig(CONFIG_USER_PHONE);
  
  if(!pUser)
  {
    pUser = temp;
  }
  if(!pSession)
  {
    pSession = temp;
  }
  if (!pMobile) {
    pMobile = temp;
  }
  sprintf(aOper->pSendData,"%s&clientversion=%s&userid=%s&sessionid=%s&moblie=%s",aOper->pSendData,APP_VER,pUser,pSession,pMobile);*/
  //end
  
	return aOper->pSendData;
}

char* QuoteLvOper_GetFuturesListUrl(QUOTELV_OPER *aOper, char *aUrl, int aFuturesType, int aPageCount,int aPageNo)
{
	if (aUrl == NULL || aPageCount < 0)
	{
		return NULL;
	}
	
	strcpy(aOper->pSendData,aUrl);
	int Len = strlen(aOper->pSendData);
	
	char sUrl[MAX_PATH];
	memset(sUrl,0,sizeof(sUrl));
	strcpy(sUrl, aOper->pSendData);
	
	if (aOper->pSendData[Len-1] != '?')
	{
		strcat(sUrl,"&");
	}
//  http://112.124.27.71:8383/b2c/tableinfo.do?reskey=allfutures&shichang=shanghai
	
	switch(aFuturesType)
	{
		case 2:		//大连
		{
			sprintf(aOper->pSendData,"%sreskey=allfutures&shichang=dalian&pagesize=%d&pageno=%d",sUrl, aPageCount,aPageNo);
		}
			break;
		case 3:		//上海
		{
			sprintf(aOper->pSendData,"%sreskey=allfutures&shichang=shanghai&pagesize=%d&pageno=%d",sUrl, aPageCount,aPageNo);
		}
			break;
		case 4:		//郑州
		{
			sprintf(aOper->pSendData,"%sreskey=allfutures&shichang=zhengzhou&pagesize=%d&pageno=%d",sUrl, aPageCount,aPageNo);
		}
			break;
		default:
			return NULL;
	}
	
	return aOper->pSendData;
}

void QuoteLvOper_SetUserIdAndSessionId(QUOTELV_OPER *aOper, char* aUserId, char* aSessionId)
{
  if(aUserId)
  {
    aOper->UserId = _a2i(aUserId);
  }
	memset(aOper->pSessionId,0,32);
  if(aSessionId)
  {
    HexToChar(aSessionId,strlen(aSessionId),aOper->pSessionId);
  }
  SocketInterface_SetUserIdAndSessionId(aOper->pSocketOper, aOper->UserId, aOper->pSessionId);
}

void QuoteLvOper_SetNewQuoteServer(QUOTELV_OPER *aOper, char* aIP, int aPort, char *aUrl, int aConType)
{
	if(aIP == NULL || aPort == 0 || aUrl == NULL)
	{
		return;
	}
	
    strcpy(aOper->pSocketAdd,aIP);
	aOper->nSocketPort = aPort;
	strcpy(aOper->pHttpUrl,aUrl);
	aOper->nConType = aConType;
  
  SocketInterface_SetServerIPPort(aOper->pSocketOper, aOper->pSocketAdd, aPort);
}

void QuoteLvOper_ConnectQuoteServer(QUOTELV_OPER *aOper)
{
  SocketInterface_Close(aOper->pSocketOper);
  SocketInterface_ConnectToServer(aOper->pSocketOper);
}

void QuoteLvOper_ConnectNewQuoteServer(QUOTELV_OPER *aOper, char* aIP, int aPort, char *aUrl, int aConType)
{
	if(aIP == NULL || aPort == 0 || aUrl == NULL)
	{
		return;
	}
  
	strcpy(aOper->pSocketAdd,aIP);
  
//  //Test
//  strcpy(aOper->pSocketAdd, "211.139.150.57");//沪港通
//  ///
	
  aOper->nSocketPort = aPort;
	strcpy(aOper->pHttpUrl,aUrl);
	aOper->nConType = aConType;
  
	SocketInterface_Close(aOper->pSocketOper);
  SocketInterface_SetServerIPPort(aOper->pSocketOper, aOper->pSocketAdd, aPort);
  SocketInterface_ConnectToServer(aOper->pSocketOper);
	HttpTools_Cancel(aOper->nHttpId);
	
	if (aOper->nConType == QUOTELV_CONNECTION_SOCKET) {
		QuoteLvOper_ResetSubscribe(aOper);
	}
	else{
		QuoteLvOper_HttpRef(aOper);
	}
	
  
}

void QuoteLvOper_SetErrCallBack(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *pError,int nStatus), void *pCBObj)
{
	aOper->pErrCBObj = pCBObj;
	aOper->pResErr = pCallBack;
}

void QuoteLvOper_SetHttpRefTime(QUOTELV_OPER *aOper, int aTime)
{
	aOper->nRefTime = aTime/1000;
}

void QuoteLvOper_HttpRef(QUOTELV_OPER *aOper)
{
	int i = 0;
	QUOTELV_SUBSCRIBE_ITEM *pItem = NULL;
	
	if (aOper->pSubscribe->nCount > 0) {
		int nLen = 256 * aOper->pSubscribe->nCount;
		char *pData = (char *) Tools_Malloc(nLen);
		int nDataLen = 0;
		char *pItemData = (char *) Tools_Malloc(512);
		
		for (i = 0; i<aOper->pSubscribe->nCount; i++) {
			pItem = QuoteLvSubscribe_GetIndexItem(aOper->pSubscribe, i);
			
			if (pItem && pItem->Id > 1000) {
				
				memset(pItemData,0,512);
				memcpy(pItemData,pItem->pData,pItem->nLen);		//需要拷贝一份发送包，不能再原来包上做修改 防止http转换成Socket时 无法连接
				pItemData[QUOTELV_PASS_LEN] = pItem->HeadType;	//重新设置请求包类型
				
				switch (pItem->AskType) {
					case RQS_LV_MIN:	//分时
					{
						QUOTELV_MIN_RES *res = (QUOTELV_MIN_RES *) pItem->pRes;
						ShortToBytes(res->nTotalCount-1,pItemData+QUOTELV_HEAD_OFFSET+7);			//针对分时只需要修改索引就可以 对应位置偏移7
						memcpy(pData+nDataLen,pItemData,pItem->nLen);
						nDataLen += pItem->nLen;
					}
						break;
					case RQS_LV_KLINE:	//K线
					{
						QUOTELV_K_RES *res = (QUOTELV_K_RES *) pItem->pRes;
						IntToBytes(res->nNewTime,pItemData+QUOTELV_HEAD_OFFSET+8);			//针对K线只需要修改日期就可以 对应位置偏移7
						memcpy(pData+nDataLen,pItemData,pItem->nLen);
						nDataLen += pItem->nLen;
					}
						break;
					case RQS_LV_RELINFO:	//个股资讯
					{
						QUOTELV_STOCKINFO_RES *res = (QUOTELV_STOCKINFO_RES *)pItem->pRes;
						Long64ToBytes(res->lNewTime, pItemData+QUOTELV_HEAD_OFFSET+8);
						memcpy(pData+nDataLen,pItemData,pItem->nLen);
						nDataLen += pItem->nLen;
					}
						break;
					case RQS_LV_GGRT:		//报价
					case RQS_LV_BOARDRANK:	//板块排行
					case RQS_LV_HKINDEXLIST:	//香港okex
					case RQS_LV_HSINDEXLIST:	//BTexokex
					case RQS_LV_BORADINDEX:		//板块okex
					case RQS_LV_ZXGRT:			//自选股
					case RQS_LV_ZHPM:			//综合排名
					case RQS_LV2_BSQUEUE:	//委托队列
					case RQS_LV2_INDVOL:	//逐笔成交量统计
					{
						memcpy(pData+nDataLen,pItemData,pItem->nLen);
						nDataLen += pItem->nLen;
					}
						break;
					case RQS_LV_DETAIL:		//明细
					case RQS_LV2_DETAIL:	//Level2 明细
					{
						QUOTELV_DETAIL_RES *res = (QUOTELV_DETAIL_RES *) pItem->pRes;
						IntToBytes(res->nZTotalCount,pItemData+QUOTELV_HEAD_OFFSET+7);			//针对明细只需要修改索引就可以 对应位置偏移7
						memcpy(pData+nDataLen,pItemData,pItem->nLen);
						nDataLen += pItem->nLen;					
					}
						break;
					case RQS_LV2_LSTNTICK:	//逐笔
					{
						QUOTELV_INDIVID_RES *res = (QUOTELV_INDIVID_RES *) pItem->pRes;
						IntToBytes(res->nIndex-1,pItemData+QUOTELV_HEAD_OFFSET+7);			//针对逐笔只需要修改索引就可以 对应位置偏移7
						memcpy(pData+nDataLen,pItemData,pItem->nLen);
						nDataLen += pItem->nLen;	
					}
						break;
					case RQS_LV2_CANCQUEUE:	//个股撤单队列
					{
						QUOTELV_CANCELTRUST_RES *res = (QUOTELV_CANCELTRUST_RES *) pItem->pRes;
						IntToBytes(res->nZTotalCount-1,pItemData+QUOTELV_HEAD_OFFSET+8);			//针对逐笔只需要修改索引就可以 对应位置偏移7
						memcpy(pData+nDataLen,pItemData,pItem->nLen);
						nDataLen += pItem->nLen;	
					}
						break;
					default:
						break;
				}
			}
		}
		
		if (nDataLen > 0) {
			aOper->nHttpId = HttpTools_GetData(aOper->nHttpId, aOper->pHttpUrl, pData, nDataLen, NULL, QuoteLvOper_HttpResedData, aOper);
		}
		
		Tools_Free((void **)&pItemData);
		Tools_Free((void **)&pData);
	}
	
}

int  QuoteLvOper_GetHotConecpt(QUOTELV_OPER *aOper, void( *pCallBack )(void *pCBObj, void *p), void *pCBObj,  long64 boardId,short queryCounts,int firstindex,short len,short sortindex,char sortmode, int aSubscribeId, TBOOL aIsSubscribe, int aArrayIndex)
{
	char * p = QuoteLvOper_PackHead(aOper,RQS_LV_HOTCONCEPT,aSubscribeId,aIsSubscribe);
	QUOTELV_HOT_DIR_ASK *ask = &aOper->hotDirAsk[aArrayIndex];
	QUOTELV_HOT_DIR_RES *res = &aOper->hotDirRes[aArrayIndex];
	aOper->nSendLen += 8+2+4+2+2+1;
  
  ask->boardId = boardId;
  ask->queryCounts = queryCounts;
  ask->firstindex = firstindex;
  ask->len = len;
  ask->sortindex = sortindex;
  ask->sortmode = sortmode;
  
  Long64ToBytes(ask->boardId,p);
	p += 8;
  ShortToBytes(ask->queryCounts,p);
	p += 2;
  IntToBytes(ask->firstindex,p);
	p += 4;
  ShortToBytes(ask->len,p);
	p += 2;
  ShortToBytes(ask->sortindex,p);
	p += 2;
  *p = ask->sortmode;
  p++;
  
	QuoteDataLV_PackAskHead(&aOper->HeadAsk,aOper->pSendData+QUOTELV_PASS_LEN);
	IntToBytes(aOper->nSendLen-5,aOper->pSendData);			//打包传输长度

	//添加到订阅id链表里
	QuoteLvSubscribe_AddItem(aOper->pSubscribe,pCallBack,pCBObj,(void*)ask, (void*)res, aOper->pSendData,aOper->nSendLen,aOper->HeadAsk.subid,aOper->nHttpId,RQS_LV_HOTCONCEPT);
	QuoteLvOper_SendData(aOper,aOper->pSendData,aOper->nSendLen);
	return aOper->HeadAsk.subid;
}

void QuoteDataLV_ParseHotData(char *aSrc, QUOTELV_HOT_DIR_RES *aHotRes){
  if(aSrc == NULL)
	{
		return;
	}
  memset(aHotRes,0,4);
  aHotRes->length = BytesToInt(aSrc,0);
  if (aHotRes->JsonData) {
    Tools_Free((void**)&aHotRes->JsonData);
  }
  aHotRes->JsonData = Tools_Malloc(aHotRes->length);
  memset(aHotRes->JsonData, 0, aHotRes->length);
  strcpy(aHotRes->JsonData, aSrc+4);
}

int QuoteLvOper_AddRecView(QUOTELV_OPER *aOper, char* aCode, char aMacketId){
  if (aCode == NULL || strlen(aCode) == 0){
    return -1;
  }
  
  int rest = -1;
  int nPos =0;
  char *tempData = NULL;
  char pContent[8];
  memset(pContent,0,8);
  
  memcpy(pContent,aCode,6);
  pContent[6] = aMacketId;
  
  int nCount = 0;
  FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pRecViewPath);
  
  if (f_data && f_data->nSize > 6){
    nCount = f_data->nSize / 7;
    
    if(nCount == 7){//删除最后的那个股
      memmove(f_data->pData+f_data->nSize-7,"",7);
      f_data->nSize -= 7;
    }
    
    while (nPos < f_data->nSize){
      if ( memcmp(f_data->pData + nPos, pContent,7)==0){
        rest = 1;
        break;
      }
      nPos += 7;
    }
    
    if (rest != 1){
      tempData = (char *)Tools_Malloc(f_data->nSize + 8);
      memcpy(tempData,pContent,7);
      memcpy(tempData+7,f_data->pData,f_data->nSize);
      
      FileTools_WriteDataEx(aOper->pRecViewPath,tempData,f_data->nSize + 7);
      Tools_Free((void **)&tempData);
      rest = 0;
    }
  }else{
    FileTools_WriteDataEx(aOper->pRecViewPath,pContent,7);
    rest = 0;
  }
  
  Tools_Free((void **)&tempData);
  FileTools_FreeData(f_data);
  return rest;
}

char* QuoteLvOper_GetAllRecView(QUOTELV_OPER *aOper){
  char *str = NULL;
  FILE_DATA* f_data = FileTools_ReadDataEx(aOper->pRecViewPath);
  
  if (f_data && f_data->nSize > 6){
    str = (char *) Tools_Malloc(f_data->nSize+8);
    _i2b(f_data->nSize, str);
//    memcpy(str+4,f_data->pData,f_data->nSize);
    memmove(str, f_data->pData, f_data->nSize);
    FileTools_FreeData(f_data);
  }
  
  return str;
}

void QuoteLvOper_DelAllRecView(QUOTELV_OPER *aOper){
  FileTools_WriteDataEx(aOper->pRecViewPath,"",0);
}
